Class: Trailblazer::Macro::Wrap
- Defined in:
- lib/trailblazer/macro/wrap.rb
Overview
Wrap exposes #inherited which will also copy the block activity. Currently, this is only used for patching (as it will try to subclass Wrap).
Class Method Summary collapse
- .call(ctx, flow_options, **circuit_options) ⇒ Object
-
.deprecate_positional_wrap_signature(user_wrap) ⇒ Object
behaves like an operation so it plays with Nested and simply calls the operation in the user-provided block.
Methods inherited from Strategy
Class Method Details
.call(ctx, flow_options, **circuit_options) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/trailblazer/macro/wrap.rb', line 60 def self.call((ctx, ), **) # since yield is called without arguments, we need to pull default params from here. Oh ... tricky. block_calling_wrapped = ->(args=[ctx, ], kwargs=) { Activity::Circuit::Runner.(block_activity, args, **kwargs) } # call the user's Wrap {} block in the operation. # This will invoke block_calling_wrapped above if the user block yields. returned = @state.get(:user_wrap).([ctx, ], **, &block_calling_wrapped) # {returned} can be # 1. {circuit interface return} from the begin block, because the wrapped OP passed # 2. {task interface return} because the user block returns "customized" signals, true of fale if returned.is_a?(Array) # 1. {circuit interface return}, new style. signal, (ctx, ) = returned else # 2. {task interface return}, only a signal (or true/false) # TODO: deprecate this? signal = returned end # If there's no mapping, use the original {signal} . # This usually means signal is a terminus or a custom signal. signal = @state.get(:signal_to_output).fetch(signal, signal) return signal, [ctx, ] end |
.deprecate_positional_wrap_signature(user_wrap) ⇒ Object
behaves like an operation so it plays with Nested and simply calls the operation in the user-provided block. class Wrapped
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/trailblazer/macro/wrap.rb', line 49 def self.deprecate_positional_wrap_signature(user_wrap) parameters = user_wrap.is_a?(Proc) || user_wrap.is_a?(Method) ? user_wrap.parameters : user_wrap.method(:call).parameters return user_wrap if parameters[0] == [:req] # means ((ctx, flow_options), *, &block), "new style" ->((ctx, ), **, &block) do warn "[Trailblazer] Wrap handlers have a new signature: ((ctx), *, &block) XXX" user_wrap.(ctx, &block) end end |