Class: Trailblazer::Activity::Schema::Intermediate
- Inherits:
-
Struct
- Object
- Struct
- Trailblazer::Activity::Schema::Intermediate
- Defined in:
- lib/trailblazer/activity/schema/intermediate.rb
Overview
An Intermediate structure defines the structure of the circuit. It usually comes from a DSL or a visual editor.
Defined Under Namespace
Instance Attribute Summary collapse
-
#start_task_ids ⇒ Object
Returns the value of attribute start_task_ids.
-
#stop_task_ids ⇒ Object
Returns the value of attribute stop_task_ids.
-
#wiring ⇒ Object
Returns the value of attribute wiring.
Class Method Summary collapse
-
.call(intermediate, implementation, config_merge: {}) ⇒ Object
Compiles a Trailblazer::Activity::Schema instance from an intermediate structure and the implementation object references.
-
.circuit(intermediate, implementation) ⇒ Object
From the intermediate “template” and the actual implementation, compile a Circuit instance.
-
.config(implementation, config:) ⇒ Object
Invoke each task’s extensions (usually coming from the DSL or some macro).
-
.connections_for(outs, task_outputs, implementation) ⇒ Object
Compute the connections for circuit_task.
- .node_attributes(intermediate, implementation) ⇒ Object
- .Out(*args) ⇒ Object
-
.outputs(stop_task_ids, nodes_attributes) ⇒ Object
intermediate/implementation independent.
- .TaskRef(id, data = {}) ⇒ Object
Instance Attribute Details
#start_task_ids ⇒ Object
Returns the value of attribute start_task_ids
5 6 7 |
# File 'lib/trailblazer/activity/schema/intermediate.rb', line 5 def start_task_ids @start_task_ids end |
#stop_task_ids ⇒ Object
Returns the value of attribute stop_task_ids
5 6 7 |
# File 'lib/trailblazer/activity/schema/intermediate.rb', line 5 def stop_task_ids @stop_task_ids end |
#wiring ⇒ Object
Returns the value of attribute wiring
5 6 7 |
# File 'lib/trailblazer/activity/schema/intermediate.rb', line 5 def wiring @wiring end |
Class Method Details
.call(intermediate, implementation, config_merge: {}) ⇒ Object
Compiles a Trailblazer::Activity::Schema instance from an intermediate structure and the implementation object references.
Intermediate structure, Implementation, calls extensions, passes config # TODO
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/trailblazer/activity/schema/intermediate.rb', line 16 def self.call(intermediate, implementation, config_merge: {}) config_default = {wrap_static: Hash.new(TaskWrap.initial_wrap_static)} # DISCUSS: this really doesn't have to be here, but works for now and we want it in 99%. config = config_default.merge(config_merge) config.freeze circuit = circuit(intermediate, implementation) nodes = node_attributes(intermediate, implementation) outputs = outputs(intermediate.stop_task_ids, nodes) config = config(implementation, config: config) Schema.new(circuit, outputs, nodes, config) end |
.circuit(intermediate, implementation) ⇒ Object
From the intermediate “template” and the actual implementation, compile a Circuit instance.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/trailblazer/activity/schema/intermediate.rb', line 29 def self.circuit(intermediate, implementation) end_events = intermediate.stop_task_ids wiring = Hash[ intermediate.wiring.collect do |task_ref, outs| task = implementation.fetch(task_ref.id) [ task.circuit_task, end_events.include?(task_ref.id) ? {} : connections_for(outs, task.outputs, implementation) ] end ] Circuit.new( wiring, intermediate.stop_task_ids.collect { |id| implementation.fetch(id).circuit_task }, start_task: intermediate.start_task_ids.collect { |id| implementation.fetch(id).circuit_task }[0] ) end |
.config(implementation, config:) ⇒ Object
Invoke each task’s extensions (usually coming from the DSL or some macro).
80 81 82 83 84 85 86 |
# File 'lib/trailblazer/activity/schema/intermediate.rb', line 80 def self.config(implementation, config:) implementation.each do |id, task| task.extensions.each { |ext| config = ext.(config: config, id: id, task: task) } # DISCUSS: ext must return new {Config}. end config end |
.connections_for(outs, task_outputs, implementation) ⇒ Object
Compute the connections for circuit_task.
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/trailblazer/activity/schema/intermediate.rb', line 51 def self.connections_for(outs, task_outputs, implementation) Hash[ outs.collect { |required_out| [ for_semantic(task_outputs, required_out.semantic).signal, implementation.fetch(required_out.target).circuit_task ] }.compact ] end |
.node_attributes(intermediate, implementation) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/trailblazer/activity/schema/intermediate.rb', line 62 def self.node_attributes(intermediate, implementation) intermediate.wiring.collect do |task_ref, outputs| # id, Task{circuit_task, outputs} task = implementation.fetch(task_ref.id) data = task_ref[:data] # TODO: allow adding data from implementation. NodeAttributes.new(task_ref.id, task.outputs, task.circuit_task, data) end end |
.Out(*args) ⇒ Object
10 |
# File 'lib/trailblazer/activity/schema/intermediate.rb', line 10 def self.Out(*args); Out.new(*args) end |
.outputs(stop_task_ids, nodes_attributes) ⇒ Object
intermediate/implementation independent.
72 73 74 75 76 77 |
# File 'lib/trailblazer/activity/schema/intermediate.rb', line 72 def self.outputs(stop_task_ids, nodes_attributes) stop_task_ids.collect do |id| # Grab the {outputs} of the stop nodes. nodes_attributes.find { |node_attrs| id == node_attrs.id }.outputs end.flatten(1) end |
.TaskRef(id, data = {}) ⇒ Object
9 |
# File 'lib/trailblazer/activity/schema/intermediate.rb', line 9 def self.TaskRef(id, data={}); TaskRef.new(id, data) end |