Module: Rung::Runner::CallHelper

Defined in:
lib/rung/runner/call_helper.rb

Overview

Helper used to run actions such as steps and callbacks.

Class Method Summary collapse

Class Method Details

.call(action, state, operation_instance, action_from_block = false, second_argument = nil, &block) ⇒ Object

Parameters:

  • action (#call, Symbol)
  • state (Rung::State)
  • operation_instance (Rung::Operation)
  • action_from_block (Boolean) (defaults to: false)
  • second_argument (defaults to: nil)

    usually used to provide step to around each callback

Raises:


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rung/runner/call_helper.rb', line 12

def call(action, state, operation_instance, action_from_block = false, second_argument = nil, &block)
  raise Error, "Can't pass block when action_from_block is enabled" if block && action_from_block

  runnable = to_runnable(action, operation_instance)
  arity = runnable.arity

  if action_from_block
    case arity
    when 0
      operation_instance.instance_exec(&runnable)
    when 1
      operation_instance.instance_exec(state, &runnable)
    else
      operation_instance.instance_exec(state, second_argument, &runnable)
    end
  else
    case arity
    when 0
      runnable.call(&block)
    when 1
      runnable.call(state, &block)
    else
      runnable.call(state, second_argument, &block)
    end
  end
end