lib/trailblazer/circuit.rb in trailblazer-circuit-0.0.3 vs lib/trailblazer/circuit.rb in trailblazer-circuit-0.0.4

- old
+ new

@@ -27,20 +27,19 @@ # This method throws exceptions when the return value of a task doesn't match # any wiring. # # @param activity A task from the circuit where to start # @param args An array of options passed to the first task. - def call(activity, args, runner: Run, **flow_options) - # TODO: args - direction = nil - flow_options = { runner: runner, debug: @name }.merge(flow_options) # DISCUSS: make this better? + def call(activity, options, flow_options={}, *args) + direction = nil + runner = flow_options[:runner] || Run loop do - direction, args, flow_options = runner.( activity, direction, args, flow_options ) + direction, options, flow_options = runner.( activity, direction, options, flow_options, *args ) # Stop execution of the circuit when we hit a stop event (< End). This could be an activity's End or Suspend. - return [ direction, args, flow_options ] if @stop_events.include?(activity) + return [ direction, options, flow_options ] if @stop_events.include?(activity) activity = next_for(activity, direction) do |next_activity, in_map| activity_name = @name[activity] || activity # TODO: this must be implemented only once, somewhere. raise IllegalInputError.new("#{@name[:id]} #{activity_name}") unless in_map raise IllegalOutputSignalError.new("from #{@name[:id]}: `#{activity_name}`===>[ #{direction.inspect} ]") unless next_activity @@ -95,21 +94,35 @@ def self.End(name, options={}) End.new(name, options) end # Builder for running a nested process from a specific `start_at` position. - def self.Nested(activity, start_with=activity[:Start]) - ->(start_at, options, *args) { - activity.(start_with, options, *args) - } + def self.Nested(*args) + Nested.new(*args) end + class Nested + def initialize(activity, start_with=activity[:Start]) + @activity, @start_with = activity, start_with + end + + def call(start_at, *args) + @activity.(@start_with, *args) + end + + attr_reader :activity + end + class Direction; end class Right < Direction; end class Left < Direction; end end end require "trailblazer/circuit/activity" require "trailblazer/circuit/task" require "trailblazer/circuit/alter" require "trailblazer/circuit/trace" +require "trailblazer/circuit/present" +require "trailblazer/circuit/wrapped" + +require "trailblazer/context"