Class: Ibex::GenerationInput
- Inherits:
-
Object
- Object
- Ibex::GenerationInput
- Defined in:
- lib/ibex/generation_input.rb
Overview
Digest and identity of source bytes actually consumed by one generation.
Instance Attribute Summary collapse
-
#access_paths ⇒ Object
readonly
: Array.
-
#bytesize ⇒ Object
readonly
: Integer.
-
#dev ⇒ Object
readonly
: Integer.
-
#ino ⇒ Object
readonly
: Integer.
-
#path ⇒ Object
readonly
: String.
-
#sha256 ⇒ Object
readonly
: String.
Instance Method Summary collapse
-
#add_access_path(path) ⇒ Object
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.
- #to_h ⇒ Object
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 ⇒ Object (readonly)
: Array
14 15 16 |
# File 'lib/ibex/generation_input.rb', line 14 def access_paths @access_paths end |
#bytesize ⇒ Object (readonly)
: Integer
11 12 13 |
# File 'lib/ibex/generation_input.rb', line 11 def bytesize @bytesize end |
#dev ⇒ Object (readonly)
: Integer
12 13 14 |
# File 'lib/ibex/generation_input.rb', line 12 def dev @dev end |
#ino ⇒ Object (readonly)
: Integer
13 14 15 |
# File 'lib/ibex/generation_input.rb', line 13 def ino @ino end |
#path ⇒ Object (readonly)
: String
9 10 11 |
# File 'lib/ibex/generation_input.rb', line 9 def path @path end |
#sha256 ⇒ Object (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) = 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 |
#to_h ⇒ Object
35 36 37 |
# File 'lib/ibex/generation_input.rb', line 35 def to_h { "path" => @path, "sha256" => @sha256, "bytesize" => @bytesize } end |