Class: Ibex::Watch::SourceSnapshot

Inherits:
Object
  • Object
show all
Defined in:
lib/ibex/watch/source_snapshot.rb

Overview

Stable metadata and content fingerprints for watched source paths.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paths) ⇒ SourceSnapshot

Returns a new instance of SourceSnapshot.



17
18
19
20
21
# File 'lib/ibex/watch/source_snapshot.rb', line 17

def initialize(paths)
  @paths = paths.map { |path| File.expand_path(path) }.uniq.sort.freeze
  @entries = @paths.to_h { |path| [path, fingerprint(path)] }.freeze #: Hash[String, fingerprint]
  freeze
end

Instance Attribute Details

#entriesObject (readonly, protected)

: Hash[String, fingerprint]



38
39
40
# File 'lib/ibex/watch/source_snapshot.rb', line 38

def entries
  @entries
end

#pathsObject (readonly)

@rbs! type fingerprint_value = Symbol | String | Integer | nil | Hash[Symbol, fingerprint_value] type fingerprint = Hash[Symbol, fingerprint_value]



14
15
16
# File 'lib/ibex/watch/source_snapshot.rb', line 14

def paths
  @paths
end

Instance Method Details

#==(other) ⇒ Object



24
25
26
# File 'lib/ibex/watch/source_snapshot.rb', line 24

def ==(other)
  @entries == other.__send__(:entries)
end

#entry(path) ⇒ Object (protected)



41
42
43
# File 'lib/ibex/watch/source_snapshot.rb', line 41

def entry(path)
  @entries[path]
end

#unchanged_since?(older) ⇒ Boolean

Every path in this snapshot must have had the same value in the older snapshot.

Returns:

  • (Boolean)


30
31
32
33
34
# File 'lib/ibex/watch/source_snapshot.rb', line 30

def unchanged_since?(older)
  @paths.all? do |path|
    older.__send__(:entry, path) == @entries.fetch(path)
  end
end