module RailwayOperation::Operator::InstanceMethods
The RailwayOperation::Operator
instance methods exposes a single method - RailwayOperation::Operator#run
This method is intended to run thpe default operation. Although it's possible to invoke ohter operations of the class the method missing approach is preffered (ie run_<operation_name>)
Public Instance Methods
run(argument, operation: :default, track_identifier: 1, step_index: 0, **info)
click to toggle source
# File lib/railway_operation/operator.rb, line 66 def run(argument, operation: :default, track_identifier: 1, step_index: 0, **info) op = self.class.operation(operation) wrap(*op.operation_surrounds) do _run( argument, Info.new(operation: op, **info), track_identifier: op.track_identifier(track_identifier), step_index: step_index ) end end
run_step(argument, operation: :default, track_identifier:, step_index:, **info)
click to toggle source
# File lib/railway_operation/operator.rb, line 79 def run_step(argument, operation: :default, track_identifier:, step_index:, **info) op = self.class.operation(operation) new_info = Info.new(operation: op, **info) new_info.execution.add_step( argument: argument, track_identifier: track_identifier, step_index: step_index ) _run_step(argument, new_info) end
Private Instance Methods
_run(argument, info, track_identifier:, step_index:)
click to toggle source
# File lib/railway_operation/operator.rb, line 130 def _run(argument, info, track_identifier:, step_index:) return [argument, info] if step_index > info.operation.last_step_index info.execution.add_step( argument: argument, track_identifier: track_identifier, step_index: step_index ) stepper_fn = info.operation.stepper_function || DEFAULT_STRATEGY vector = Stepper.step(stepper_fn, info) do _run_step(argument, info) end _run( vector[:argument].(info), info, track_identifier: vector[:track_identifier].(info), step_index: vector[:step_index].(info) ) end
_run_step(argument, info)
click to toggle source
# File lib/railway_operation/operator.rb, line 94 def _run_step(argument, info) step = info.execution.last step_definition = info.operation[step.track_identifier, step.step_index] unless step_definition step.noop! return [argument, info] end step.start! surrounds = info.operation.step_surrounds[step.track_identifier] + info.operation.step_surrounds['*'] wrap_arguments = [DeepClone.clone(argument), info] step[:method] = step_definition step[:noop] = false step[:argument] = wrap(*surrounds, arguments: wrap_arguments) do case step_definition when Symbol # add_step 1, :method public_send(step_definition, *wrap_arguments) when Array # add_step 1, [MyClass, :method] step_definition[0].send(step_definition[1], *wrap_arguments) else # add_step 1, ->(argument, info) { ... } step_definition.call(*wrap_arguments) end end step.end! [step[:argument], info] end