Class: Igniter::Extensions::Contracts::Provenance::NodeTrace

Inherits:
Object
  • Object
show all
Defined in:
lib/igniter/extensions/contracts/provenance/node_trace.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, kind:, value:, contributing: {}) ⇒ NodeTrace

Returns a new instance of NodeTrace.



10
11
12
13
14
15
16
# File 'lib/igniter/extensions/contracts/provenance/node_trace.rb', line 10

def initialize(name:, kind:, value:, contributing: {})
  @name = name.to_sym
  @kind = kind.to_sym
  @value = value
  @contributing = contributing.freeze
  freeze
end

Instance Attribute Details

#contributingObject (readonly)

Returns the value of attribute contributing.



8
9
10
# File 'lib/igniter/extensions/contracts/provenance/node_trace.rb', line 8

def contributing
  @contributing
end

#kindObject (readonly)

Returns the value of attribute kind.



8
9
10
# File 'lib/igniter/extensions/contracts/provenance/node_trace.rb', line 8

def kind
  @kind
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/igniter/extensions/contracts/provenance/node_trace.rb', line 8

def name
  @name
end

#valueObject (readonly)

Returns the value of attribute value.



8
9
10
# File 'lib/igniter/extensions/contracts/provenance/node_trace.rb', line 8

def value
  @value
end

Instance Method Details

#contributing_inputsObject



26
27
28
29
30
31
32
# File 'lib/igniter/extensions/contracts/provenance/node_trace.rb', line 26

def contributing_inputs
  return { name => value } if input?

  contributing.each_value.with_object({}) do |trace, memo|
    memo.merge!(trace.contributing_inputs)
  end
end

#input?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/igniter/extensions/contracts/provenance/node_trace.rb', line 18

def input?
  kind == :input
end

#leaf?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/igniter/extensions/contracts/provenance/node_trace.rb', line 22

def leaf?
  contributing.empty?
end

#path_to(input_name) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/igniter/extensions/contracts/provenance/node_trace.rb', line 38

def path_to(input_name)
  target = input_name.to_sym
  return [name] if name == target

  contributing.each_value do |trace|
    path = trace.path_to(target)
    return [name] + path if path
  end

  nil
end

#sensitive_to?(input_name) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/igniter/extensions/contracts/provenance/node_trace.rb', line 34

def sensitive_to?(input_name)
  contributing_inputs.key?(input_name.to_sym)
end