class Rung::Runner::Runner
Public Class Methods
new(operation_instance, initial_state)
click to toggle source
# File lib/rung/runner/runner.rb, line 4 def initialize(operation_instance, initial_state) @context = RunContext.new(operation_instance, {}.merge(initial_state)) end
Public Instance Methods
call()
click to toggle source
# File lib/rung/runner/runner.rb, line 14 def call with_callbacks(around_callbacks) { iterate(steps_definition) } current_state end
Private Instance Methods
call_nested_step(nested)
click to toggle source
# File lib/rung/runner/runner.rb, line 52 def call_nested_step(nested) CallHelper.call nested.action, current_state, operation_instance do iterate nested.nested_steps end end
call_simple_step(step)
click to toggle source
# File lib/rung/runner/runner.rb, line 58 def call_simple_step(step) CallHelper.call step.action, current_state, operation_instance, step.from_block end
call_step(step)
click to toggle source
# File lib/rung/runner/runner.rb, line 48 def call_step(step) step.nested? ? call_nested_step(step) : call_simple_step(step) end
current_state()
click to toggle source
# File lib/rung/runner/runner.rb, line 63 def current_state @context.to_state end
handle_failure(step)
click to toggle source
# File lib/rung/runner/runner.rb, line 67 def handle_failure(step) fail! unless step.ignore_result? stop! if step.fail_fast? end
iterate(steps_definition)
click to toggle source
# File lib/rung/runner/runner.rb, line 31 def iterate(steps_definition) steps_definition.each(&method(:run_step)) success? end
run_step(step)
click to toggle source
# File lib/rung/runner/runner.rb, line 37 def run_step(step) return if stopped? return unless step.run?(success?) step_success = with_callbacks( around_each_callbacks, second_argument: step ) { call_step(step) } handle_failure(step) unless step_success end
with_callbacks(callbacks, second_argument: nil, &block)
click to toggle source
# File lib/rung/runner/runner.rb, line 22 def with_callbacks(callbacks, second_argument: nil, &block) callbacks.reverse.inject(block) do |inner, callback| lambda do CallHelper.call callback.action, current_state, operation_instance, callback.from_block, second_argument, &inner end end.call end