Class: Trailblazer::Activity::TaskBuilder::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/trailblazer/activity/task_builder.rb

Overview

Wraps a task (that usually expects the task interface) into a circuit interface that can be used directly in a Circuit. We expect task to be exposing an Option() interface when calling it.

Instance Method Summary collapse

Constructor Details

#initialize(task, user_proc) ⇒ Task

Returns a new instance of Task.



25
26
27
28
29
# File 'lib/trailblazer/activity/task_builder.rb', line 25

def initialize(task, user_proc)
  @task            = task
  @user_proc       = user_proc
  freeze
end

Instance Method Details

#call(ctx, flow_options, **circuit_options) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/trailblazer/activity/task_builder.rb', line 31

def call((ctx, flow_options), **circuit_options)
  # Execute the user step with TRB's kw args.
  # {@task} is/implements {Trailblazer::Option} interface.
  result = call_option(@task, [ctx, flow_options], **circuit_options)

  # Return an appropriate signal which direction to go next.
  signal = Activity::TaskBuilder.binary_signal_for(result, Activity::Right, Activity::Left)

  return signal, [ctx, flow_options]
end

#inspectObject Also known as: to_s

TODO: make me private!



47
48
49
# File 'lib/trailblazer/activity/task_builder.rb', line 47

def inspect # TODO: make me private!
  %{#<Trailblazer::Activity::TaskBuilder::Task user_proc=#{Trailblazer::Activity::Introspect.render_task(@user_proc)}>}
end