Class: Ibex::GenerationInput

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of GenerationInput.

RBS:

  • (String path, String source, ?access_path: String) -> void

Parameters:

  • path (String)
  • source (String)
  • access_path: (String) (defaults to: path)


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_pathsArray[String] (readonly)

Signature:

  • Array[String]

Returns:

  • (Array[String])


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

def access_paths
  @access_paths
end

#bytesizeInteger (readonly)

Signature:

  • Integer

Returns:

  • (Integer)


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

def bytesize
  @bytesize
end

#devInteger (readonly)

Signature:

  • Integer

Returns:

  • (Integer)


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

def dev
  @dev
end

#inoInteger (readonly)

Signature:

  • Integer

Returns:

  • (Integer)


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

def ino
  @ino
end

#pathString (readonly)

Signature:

  • String

Returns:

  • (String)


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

def path
  @path
end

#sha256String (readonly)

Signature:

  • String

Returns:

  • (String)


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.

RBS:

  • (String path) -> void

Parameters:

  • path (String)


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.

RBS:

  • () -> bool

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

#lexical_paths_current?Boolean

RBS:

  • () -> bool

Returns:

  • (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_hHash[String, untyped]

RBS:

  • () -> Hash[String, untyped]

Returns:

  • (Hash[String, untyped])


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

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