Module: Trailblazer::Activity::Magnetic::DSL::ProcessOptions
- Defined in:
- lib/trailblazer/activity/dsl/magnetic/process_options.rb
Overview
Class Method Summary collapse
-
.call(id, options, plus_poles, &block) ⇒ PlusPole
Output => target (End/“id”/:color) options: { DSL::Output => target }.
- .output_for(semantic, plus_poles) ⇒ Object
- .process_tuple(id, output, task, plus_poles, &block) ⇒ Object
Class Method Details
.call(id, options, plus_poles, &block) ⇒ PlusPole
Output => target (End/“id”/:color) options:
{ DSL::Output[::Semantic] => target }
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/trailblazer/activity/dsl/magnetic/process_options.rb', line 18 def call(id, , plus_poles, &block) polarization, adds = . collect { |key, task| # this method call is the only thing that really matters here. # TODO: make this transformation a bit more obvious. process_tuple(id, key, task, plus_poles, &block) }. inject([[],[]]) { |memo, (polarization, adds)| memo[0]<<polarization; memo[1]<<adds; memo } return polarization, adds.flatten(1) end |
.output_for(semantic, plus_poles) ⇒ Object
68 69 70 71 72 |
# File 'lib/trailblazer/activity/dsl/magnetic/process_options.rb', line 68 def output_for(semantic, plus_poles) # DISCUSS: review PlusPoles#[] output, _ = plus_poles.instance_variable_get(:@plus_poles)[semantic.value] output or raise("Couldn't find existing output for `#{semantic.value.inspect}`.") end |
.process_tuple(id, output, task, plus_poles, &block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/trailblazer/activity/dsl/magnetic/process_options.rb', line 30 def process_tuple(id, output, task, plus_poles, &block) output = output_for(output, plus_poles) if output.kind_of?(Activity::DSL::OutputSemantic) if task.kind_of?(Activity::End) # raise %{An end event with semantic `#{task.to_h[:semantic]}` has already been added. Please use an ID reference: `=> "End.#{task.to_h[:semantic]}"`} if new_edge = "#{id}-#{output.signal}" [ Polarization.new( output: output, color: new_edge ), [ [:add, [task.to_h[:semantic], [ [new_edge], task, [] ], group: :end]] ] ] # procs come from DSL calls such as `Path() do ... end`. elsif task.is_a?(Proc) start_color, activity = task.(block) adds = activity.to_h[:adds] [ Polarization.new( output: output, color: start_color ), # TODO: this is a pseudo-"merge" and should be public API at some point. # TODO: we also need to merge all the other states such as debug. adds[1..-1] # drop start ] elsif task.is_a?(Activity::DSL::Track) # An additional plus polarization. Example: Output => :success [ Polarization.new( output: output, color: task.color ) ] else # ID: existing step new_edge = "#{id}-#{output.signal}-#{task}" # edge from <id> to <target> [ Polarization.new( output: output, color: new_edge ), [[ :magnetic_to, [ task, [new_edge] ] ]], # mark target (`task`) as magnetic to the new edge. ] end end |