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.
42 43 44 45 46 47 48 |
# File 'lib/dynflow/execution_plan/output_reference.rb', line 42 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.
40 41 42 |
# File 'lib/dynflow/execution_plan/output_reference.rb', line 40 def action_id @action_id end |
#execution_plan_id ⇒ Object (readonly)
Returns the value of attribute execution_plan_id.
40 41 42 |
# File 'lib/dynflow/execution_plan/output_reference.rb', line 40 def execution_plan_id @execution_plan_id end |
#step_id ⇒ Object (readonly)
Returns the value of attribute step_id.
40 41 42 |
# File 'lib/dynflow/execution_plan/output_reference.rb', line 40 def step_id @step_id end |
#subkeys ⇒ Object (readonly)
Returns the value of attribute subkeys.
40 41 42 |
# File 'lib/dynflow/execution_plan/output_reference.rb', line 40 def subkeys @subkeys end |
Class Method Details
.dereference(object, persistence) ⇒ Object
dereferences all OutputReferences in Hash-Array structure
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/dynflow/execution_plan/output_reference.rb', line 7 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
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/dynflow/execution_plan/output_reference.rb', line 23 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
50 51 52 |
# File 'lib/dynflow/execution_plan/output_reference.rb', line 50 def [](subkey) self.class.new(execution_plan_id, step_id, action_id, subkeys + [subkey]) end |
#dereference(persistence) ⇒ Object
70 71 72 73 |
# File 'lib/dynflow/execution_plan/output_reference.rb', line 70 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
54 55 56 57 58 59 60 |
# File 'lib/dynflow/execution_plan/output_reference.rb', line 54 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
62 63 64 65 66 |
# File 'lib/dynflow/execution_plan/output_reference.rb', line 62 def to_s "Step(#{step_id}).output".dup.tap do |ret| ret << subkeys.map { |k| "[:#{k}]" }.join('') if subkeys.any? end end |