Class: Trailblazer::Activity::Circuit::TaskAdapter
- Inherits:
-
Object
- Object
- Trailblazer::Activity::Circuit::TaskAdapter
- Defined in:
- lib/trailblazer/activity/circuit/task_adapter.rb
Direct Known Subclasses
Class Method Summary collapse
-
.binary_signal_for(result, on_true, on_false) ⇒ Object
Translates the return value of the user step into a valid signal.
-
.for_step(step, binary: true, **options_for_step) ⇒ TaskAdapter
Returns a ‘TaskAdapter` instance always exposes the complete circuit-interface, and can be used directly in a Trailblazer::Activity::Circuit.
Instance Method Summary collapse
- #call(ctx, flow_options, **circuit_options) ⇒ Object
-
#initialize(circuit_step) ⇒ TaskAdapter
constructor
A new instance of TaskAdapter.
-
#inspect ⇒ Object
(also: #to_s)
TODO: make me private!.
Constructor Details
#initialize(circuit_step) ⇒ TaskAdapter
Returns a new instance of TaskAdapter.
68 69 70 |
# File 'lib/trailblazer/activity/circuit/task_adapter.rb', line 68 def initialize(circuit_step, **) @circuit_step = circuit_step end |
Class Method Details
.binary_signal_for(result, on_true, on_false) ⇒ Object
Translates the return value of the user step into a valid signal. Note that it passes through subclasses of Signal.
83 84 85 86 87 88 89 |
# File 'lib/trailblazer/activity/circuit/task_adapter.rb', line 83 def self.binary_signal_for(result, on_true, on_false) if result.is_a?(Class) && result < Activity::Signal result else result ? on_true : on_false end end |
.for_step(step, binary: true, **options_for_step) ⇒ TaskAdapter
Note:
This used to be called ‘TaskBuilder::Task`.
Returns a ‘TaskAdapter` instance always exposes the complete circuit-interface, and can be used directly in a Trailblazer::Activity::Circuit.
61 62 63 64 65 |
# File 'lib/trailblazer/activity/circuit/task_adapter.rb', line 61 def self.for_step(step, binary: true, **) circuit_step = Circuit.Step(step, **) new(circuit_step) end |
Instance Method Details
#call(ctx, flow_options, **circuit_options) ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/trailblazer/activity/circuit/task_adapter.rb', line 72 def call((ctx, ), **) result, ctx = @circuit_step.([ctx, ], **) # Return an appropriate signal which direction to go next. signal = TaskAdapter.binary_signal_for(result, Activity::Right, Activity::Left) return signal, [ctx, ] end |
#inspect ⇒ Object Also known as: to_s
TODO: make me private!
91 92 93 94 95 |
# File 'lib/trailblazer/activity/circuit/task_adapter.rb', line 91 def inspect # TODO: make me private! user_step = @circuit_step.instance_variable_get(:@user_proc) # DISCUSS: to we want Step#to_h? %(#<Trailblazer::Activity::TaskBuilder::Task user_proc=#{Trailblazer::Activity::Introspect.render_task(user_step)}>) end |