Class: Ibex::GenerationInput

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

Overview

Digest and identity of source bytes actually consumed by one generation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, source, access_path: path) ⇒ GenerationInput

Returns a new instance of GenerationInput.



17
18
19
20
21
22
23
24
25
# File 'lib/ibex/generation_input.rb', line 17

def initialize(path, source, access_path: path)
  @path = File.realpath(path).freeze
  stat = File.stat(@path)
  @sha256 = Digest::SHA256.hexdigest(source).freeze
  @bytesize = source.bytesize
  @dev = stat.dev
  @ino = stat.ino
  @access_paths = [File.expand_path(access_path)] #: Array[String]
end

Instance Attribute Details

#access_pathsObject (readonly)

: Array



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

def access_paths
  @access_paths
end

#bytesizeObject (readonly)

: Integer



11
12
13
# File 'lib/ibex/generation_input.rb', line 11

def bytesize
  @bytesize
end

#devObject (readonly)

: Integer



12
13
14
# File 'lib/ibex/generation_input.rb', line 12

def dev
  @dev
end

#inoObject (readonly)

: Integer



13
14
15
# File 'lib/ibex/generation_input.rb', line 13

def ino
  @ino
end

#pathObject (readonly)

: String



9
10
11
# File 'lib/ibex/generation_input.rb', line 9

def path
  @path
end

#sha256Object (readonly)

: String



10
11
12
# File 'lib/ibex/generation_input.rb', line 10

def sha256
  @sha256
end

Instance Method Details

#add_access_path(path) ⇒ Object

Record another lexical path that supplied these canonical bytes.



29
30
31
32
# File 'lib/ibex/generation_input.rb', line 29

def add_access_path(path)
  expanded = File.expand_path(path)
  @access_paths << expanded unless @access_paths.include?(expanded)
end

#current?Boolean

Detect content changes even when size and timestamps are preserved.

Returns:

  • (Boolean)


41
42
43
44
45
46
47
48
# File 'lib/ibex/generation_input.rb', line 41

def current?
  source = File.binread(@path)
  stat = File.stat(@path)
  lexical_paths_current? && stat.dev == @dev && stat.ino == @ino &&
    source.bytesize == @bytesize && Digest::SHA256.hexdigest(source) == @sha256
rescue SystemCallError
  false
end

#to_hObject



35
36
37
# File 'lib/ibex/generation_input.rb', line 35

def to_h
  { "path" => @path, "sha256" => @sha256, "bytesize" => @bytesize }
end