Method: Trailblazer::Macro.Nested
- Defined in:
- lib/trailblazer/macro/nested.rb
.Nested(callable, id: Macro.id_for(callable, macro: :Nested, hint: callable), auto_wire: []) ⇒ Object
Nested macro. DISCUSS: rename auto_wire => static
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/trailblazer/macro/nested.rb', line 5 def self.Nested(callable, id: Macro.id_for(callable, macro: :Nested, hint: callable), auto_wire: []) # Warn developers when they confuse Nested with Subprocess (for simple nesting, without a dynamic decider). if callable.is_a?(Class) && callable < Nested.operation_class caller_locations = caller_locations(1, 2) caller_location = caller_locations[0].to_s =~ /forwardable/ ? caller_locations[1] : caller_locations[0] Activity::Deprecate.warn caller_location, "Using the `Nested()` macro without a dynamic decider is deprecated.\n" \ "To simply nest an activity or operation, replace `Nested(#{callable})` with `Subprocess(#{callable})`.\n" \ "Check the Subprocess API docs to learn more about nesting: https://trailblazer.to/2.1/docs/activity.html#activity-wiring-api-subprocess" return Activity::Railway.Subprocess(callable) end task = if auto_wire.any? Nested.Static(callable, id: id, auto_wire: auto_wire) else # no {auto_wire} Nested.Dynamic(callable, id: id) end # |-- Nested.compute_nested_activity...Trailblazer::Macro::Nested::Decider # `-- task_wrap.call_task..............Method merge = [ [Nested::Decider.new(callable), id: "Nested.compute_nested_activity", prepend: "task_wrap.call_task"], ] task_wrap_extension = Activity::TaskWrap::Extension::WrapStatic.new(extension: Activity::TaskWrap::Extension(*merge)) Activity::Railway.Subprocess(task).merge( # FIXME: allow this directly in Subprocess id: id, extensions: [task_wrap_extension], ) end |