Class: Dynflow::ExecutionPlan::OutputReference
- Inherits:
-
Serializable
- Object
- Serializable
- Dynflow::ExecutionPlan::OutputReference
- Includes:
- Algebrick::TypeCheck
- Defined in:
- lib/dynflow/execution_plan/output_reference.rb
Constant Summary
Constants inherited from Serializable
Serializable::LEGACY_TIME_FORMAT, Serializable::TIME_FORMAT
Instance Attribute Summary collapse
-
#action_id ⇒ Object
readonly
Returns the value of attribute action_id.
-
#execution_plan_id ⇒ Object
readonly
Returns the value of attribute execution_plan_id.
-
#step_id ⇒ Object
readonly
Returns the value of attribute step_id.
-
#subkeys ⇒ Object
readonly
Returns the value of attribute subkeys.
Class Method Summary collapse
-
.dereference(object, persistence) ⇒ Object
dereferences all OutputReferences in Hash-Array structure.
-
.deserialize(value) ⇒ Object
dereferences all hashes representing OutputReferences in Hash-Array structure.
Instance Method Summary collapse
- #[](subkey) ⇒ Object
- #dereference(persistence) ⇒ Object
-
#initialize(execution_plan_id, step_id, action_id, subkeys = []) ⇒ OutputReference
constructor
A new instance of OutputReference.
- #to_hash ⇒ Object
- #to_s ⇒ Object (also: #inspect)
Methods inherited from Serializable
Constructor Details
#initialize(execution_plan_id, step_id, action_id, subkeys = []) ⇒ OutputReference
Returns a new instance of OutputReference.
43 44 45 46 47 48 49 |
# File 'lib/dynflow/execution_plan/output_reference.rb', line 43 def initialize(execution_plan_id, step_id, action_id, subkeys = []) @execution_plan_id = Type! execution_plan_id, String @step_id = Type! step_id, Integer @action_id = Type! action_id, Integer Type! subkeys, Array @subkeys = subkeys.map { |v| Type!(v, String, Symbol).to_s }.freeze end |
Instance Attribute Details
#action_id ⇒ Object (readonly)
Returns the value of attribute action_id.
41 42 43 |
# File 'lib/dynflow/execution_plan/output_reference.rb', line 41 def action_id @action_id end |
#execution_plan_id ⇒ Object (readonly)
Returns the value of attribute execution_plan_id.
41 42 43 |
# File 'lib/dynflow/execution_plan/output_reference.rb', line 41 def execution_plan_id @execution_plan_id end |
#step_id ⇒ Object (readonly)
Returns the value of attribute step_id.
41 42 43 |
# File 'lib/dynflow/execution_plan/output_reference.rb', line 41 def step_id @step_id end |
#subkeys ⇒ Object (readonly)
Returns the value of attribute subkeys.
41 42 43 |
# File 'lib/dynflow/execution_plan/output_reference.rb', line 41 def subkeys @subkeys end |
Class Method Details
.dereference(object, persistence) ⇒ Object
dereferences all OutputReferences in Hash-Array structure
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/dynflow/execution_plan/output_reference.rb', line 8 def self.dereference(object, persistence) case object when Hash object.reduce(Utils.indifferent_hash({})) do |h, (key, val)| h.update(key => dereference(val, persistence)) end when Array object.map { |val| dereference(val, persistence) } when self object.dereference(persistence) else object end end |
.deserialize(value) ⇒ Object
dereferences all hashes representing OutputReferences in Hash-Array structure
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dynflow/execution_plan/output_reference.rb', line 24 def self.deserialize(value) case value when Hash if value[:class] == self.to_s new_from_hash(value) else value.reduce(Utils.indifferent_hash({})) do |h, (key, val)| h.update(key => deserialize(val)) end end when Array value.map { |val| deserialize(val) } else value end end |
Instance Method Details
#[](subkey) ⇒ Object
51 52 53 |
# File 'lib/dynflow/execution_plan/output_reference.rb', line 51 def [](subkey) self.class.new(execution_plan_id, step_id, action_id, subkeys + [subkey]) end |
#dereference(persistence) ⇒ Object
71 72 73 74 |
# File 'lib/dynflow/execution_plan/output_reference.rb', line 71 def dereference(persistence) action_data = persistence.adapter.load_action(execution_plan_id, action_id) @subkeys.reduce(action_data[:output]) { |v, k| v.fetch k } end |
#to_hash ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/dynflow/execution_plan/output_reference.rb', line 55 def to_hash recursive_to_hash class: self.class.to_s, execution_plan_id: execution_plan_id, step_id: step_id, action_id: action_id, subkeys: subkeys end |
#to_s ⇒ Object Also known as: inspect
63 64 65 66 67 |
# File 'lib/dynflow/execution_plan/output_reference.rb', line 63 def to_s "Step(#{step_id}).output".dup.tap do |ret| ret << subkeys.map { |k| "[:#{k}]" }.join('') if subkeys.any? end end |