class RailwayOperation::Stepper
This class is responsible for calculating the vector of the next step during an operation execution
Public Class Methods
step(*args, &block)
click to toggle source
# File lib/railway_operation/stepper.rb, line 37 def self.step(*args, &block) new.step(*args, &block) end
Public Instance Methods
[](key)
click to toggle source
# File lib/railway_operation/stepper.rb, line 33 def [](key) vector[key] end
continue()
click to toggle source
Manipulators
# File lib/railway_operation/stepper.rb, line 48 def continue vector end
fail_operation()
click to toggle source
# File lib/railway_operation/stepper.rb, line 98 def fail_operation vector.merge!( argument: Argument::INITIAL, track_identifier: TrackIdentifier::NOOP ) self end
halt_operation()
click to toggle source
# File lib/railway_operation/stepper.rb, line 89 def halt_operation vector.merge!( argument: Argument::DEFAULT, track_identifier: TrackIdentifier::NOOP ) self end
raise_error(e, info)
click to toggle source
# File lib/railway_operation/stepper.rb, line 113 def raise_error(e, info) info.execution.last_step[:succeeded] = false step_index = info.execution.length - 1 track_identifier = info.execution.last_step[:track_identifier] message = "The operation was aborted because `#{e.class}' "\ "was raised on track #{track_identifier}, step #{step_index} of the operation."\ "\n\n#{info.display}\n\n" raise e, message, e.backtrace end
restart_operation()
click to toggle source
# File lib/railway_operation/stepper.rb, line 80 def restart_operation vector.merge!( argument: Argument::INITIAL, track_identifier: TrackIdentifier::INITIAL ) self end
retry_step()
click to toggle source
# File lib/railway_operation/stepper.rb, line 71 def retry_step vector.merge!( argument: Argument::PREVIOUS, track_identifier: TrackIdentifier::DEFAULT ) self end
step(stepper_function, info, &step_executor)
click to toggle source
# File lib/railway_operation/stepper.rb, line 41 def step(stepper_function, info, &step_executor) stepper_function.call(self, info, &step_executor) self end
successor_track()
click to toggle source
# File lib/railway_operation/stepper.rb, line 107 def successor_track lambda do |operation, current_track| operation.successor_track(current_track) end end
switch_to(specified_track)
click to toggle source
# File lib/railway_operation/stepper.rb, line 52 def switch_to(specified_track) vector[:track_identifier] = lambda do |execution:, operation:, **| begin track = case specified_track when Proc specified_track.call(operation, execution.last.track_identifier) else specified_track end operation.track_index(track) # ensures that track index is found in the operation track rescue Operation::NonExistentTrack raise "Invalid stepper_function specification for '#{operation.name}'"\ "operation: invalid `switch_to(#{track})`" end end end
vector()
click to toggle source
# File lib/railway_operation/stepper.rb, line 25 def vector @vector ||= { argument: Argument::DEFAULT, step_index: StepIndex::DEFAULT, track_identifier: TrackIdentifier::DEFAULT } end