Class: Trailblazer::Macro::Nested

Inherits:
Activity::Railway
  • Object
show all
Defined in:
lib/trailblazer/macro/nested.rb

Overview

We don’t need to override Strategy.call here to prevent :exec_context from being changed. The decider is run in the taskWrap before the Nested subclass is actually called.

Defined Under Namespace

Modules: Static Classes: Decider, Dynamic

Class Method Summary collapse

Class Method Details

.Dynamic(decider, id:) ⇒ Object

Dynamic is without auto_wire where we don’t even know what could be the actual nested activity until it’s runtime.



76
77
78
79
80
81
# File 'lib/trailblazer/macro/nested.rb', line 76

def self.Dynamic(decider, id:)
  _task = Class.new(Macro::Nested) do
    step task: Dynamic.method(:call_dynamic_nested_activity),
         id:   :call_dynamic_nested_activity
  end
end

.operation_classObject

TODO: remove once we don’t need the deprecation anymore.



46
47
48
# File 'lib/trailblazer/macro/nested.rb', line 46

def self.operation_class # TODO: remove once we don't need the deprecation anymore.
  Trailblazer::Activity::DSL::Linear::Strategy
end

.Static(decider, id:, auto_wire:) ⇒ Object

Code to handle [:auto_wire]. This is called “static” as you configure the possible activities at compile-time. This is the recommended way.

TODO: allow configuring Output of Nested per internal nested activity, e.g.

  step Nested(.., Id3Tag => {Output(:invalid_metadata) => ...}
this will help when semantics overlap.


129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/trailblazer/macro/nested.rb', line 129

def self.Static(decider, id:, auto_wire:)
  decider_outputs = auto_wire.collect do |activity|
    [Activity::Railway.Output(activity, "decision:#{activity}"), Activity::Railway.Track(activity)]
  end.to_h

  _task = Class.new(Macro::Nested) do
    step(
      {
        task: Static.method(:return_route_signal),
        id:   :route_to_nested_activity, # returns the {nested_activity} signal
      }.merge(decider_outputs)
    )

    auto_wire.each do |activity|
      activity_step = Subprocess(activity)

      outputs = activity_step[:outputs]

      # TODO: detect if we have two identical "special" termini.
      output_wirings = outputs.collect do |semantic, output|
        [Output(semantic), End(semantic)] # this will add a new termins to this activity.
      end.to_h

      # Each nested activity is a Subprocess.
      # They have Output(semantic) => End(semantic) for each of their termini.
      step activity_step,
        {magnetic_to: activity}.merge(output_wirings)
        # failure and success are wired to respective termini of {nesting_activity}.
    end
  end
end