Class: Ibex::GenerationInput
- Inherits:
-
Object
- Object
- Ibex::GenerationInput
- Defined in:
- lib/ibex/generation_input.rb,
sig/ibex/generation_input.rbs
Overview
Digest and identity of source bytes actually consumed by one generation.
Instance Attribute Summary collapse
- #access_paths ⇒ Array[String] readonly
- #bytesize ⇒ Integer readonly
- #dev ⇒ Integer readonly
- #ino ⇒ Integer readonly
- #path ⇒ String readonly
- #sha256 ⇒ String readonly
Instance Method Summary collapse
-
#add_access_path(path) ⇒ void
Record another lexical path that supplied these canonical bytes.
-
#current? ⇒ Boolean
Detect content changes even when size and timestamps are preserved.
-
#initialize(path, source, access_path: path) ⇒ GenerationInput
constructor
A new instance of GenerationInput.
- #lexical_paths_current? ⇒ Boolean
- #to_h ⇒ Hash[String, untyped]
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.(access_path)] #: Array[String] end |
Instance Attribute Details
#access_paths ⇒ Array[String] (readonly)
14 15 16 |
# File 'lib/ibex/generation_input.rb', line 14 def access_paths @access_paths end |
#bytesize ⇒ Integer (readonly)
11 12 13 |
# File 'lib/ibex/generation_input.rb', line 11 def bytesize @bytesize end |
#dev ⇒ Integer (readonly)
12 13 14 |
# File 'lib/ibex/generation_input.rb', line 12 def dev @dev end |
#ino ⇒ Integer (readonly)
13 14 15 |
# File 'lib/ibex/generation_input.rb', line 13 def ino @ino end |
#path ⇒ String (readonly)
9 10 11 |
# File 'lib/ibex/generation_input.rb', line 9 def path @path end |
#sha256 ⇒ String (readonly)
10 11 12 |
# File 'lib/ibex/generation_input.rb', line 10 def sha256 @sha256 end |
Instance Method Details
#add_access_path(path) ⇒ void
This method returns an undefined value.
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) = File.(path) @access_paths << unless @access_paths.include?() end |
#current? ⇒ Boolean
Detect content changes even when size and timestamps are preserved.
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 |
#lexical_paths_current? ⇒ Boolean
53 54 55 |
# File 'lib/ibex/generation_input.rb', line 53 def lexical_paths_current? @access_paths.all? { |path| File.realpath(path) == @path } end |
#to_h ⇒ Hash[String, untyped]
35 36 37 |
# File 'lib/ibex/generation_input.rb', line 35 def to_h { "path" => @path, "sha256" => @sha256, "bytesize" => @bytesize } end |