Method: Trailblazer::Macro.Wrap
- Defined in:
- lib/trailblazer/macro/wrap.rb
.Wrap(user_wrap, id: Macro.id_for(user_wrap, macro: :Wrap), &block) ⇒ Object
TODO: user_wrap: rename to wrap_handler.
4 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 39 40 41 |
# File 'lib/trailblazer/macro/wrap.rb', line 4 def self.Wrap(user_wrap, id: Macro.id_for(user_wrap, macro: :Wrap), &block) user_wrap = Wrap.deprecate_positional_wrap_signature(user_wrap) block_activity, outputs = Macro.block_activity_for(nil, &block) outputs = Hash[outputs.collect { |output| [output.semantic, output] }] # FIXME: redundant to Subprocess(). # Since in the user block, you can return Railway.pass! etc, we need to map # those to the actual wrapped block_activity's end. signal_to_output = { Activity::Right => outputs[:success].signal, Activity::Left => outputs[:failure].signal, Activity::FastTrack::PassFast => outputs[:pass_fast].signal, Activity::FastTrack::FailFast => outputs[:fail_fast].signal, true => outputs[:success].signal, false => outputs[:failure].signal, nil => outputs[:failure].signal, } state = Declarative::State( # this is important, so we subclass the actually wrapped activity when {Wrap} is subclassed. block_activity: [block_activity, {copy: Trailblazer::Declarative::State.method(:subclass)}], user_wrap: [user_wrap, {}], # DISCUSS: we could even allow the wrap_handler to be patchable. signal_to_output: [signal_to_output, {}], ) task = Class.new(Wrap) do extend Macro::Strategy::State # now, the Wrap subclass can inherit its state and copy the {block_activity}. initialize!(state) end # DISCUSS: unfortunately, Ruby doesn't allow to set this during {Class.new}. { task: task, id: id, outputs: outputs, } end |