module Rung::Definition::StepsDSL

Public Instance Methods

add_generic_step(action, options = {}, &block) click to toggle source
# File lib/rung/definition/steps_dsl.rb, line 8
def add_generic_step(action, options = {}, &block)
  step = step_from_definition action, **options, &block
  steps_definition.push step
end
always(*args, &block) click to toggle source
# File lib/rung/definition/steps_dsl.rb, line 25
def always(*args, &block)
  add_step_from_args args, run_on: :any, ignore_result: true, &block
end
failure(*args, &block) click to toggle source
# File lib/rung/definition/steps_dsl.rb, line 21
def failure(*args, &block)
  add_step_from_args args, run_on: :failure, ignore_result: true, &block
end
step(*args, &block) click to toggle source
# File lib/rung/definition/steps_dsl.rb, line 13
def step(*args, &block)
  add_step_from_args args, &block
end
steps_definition() click to toggle source
# File lib/rung/definition/steps_dsl.rb, line 4
def steps_definition
  @steps_definition ||= []
end
tee(*args, &block) click to toggle source
# File lib/rung/definition/steps_dsl.rb, line 17
def tee(*args, &block)
  add_step_from_args args, ignore_result: true, &block
end

Private Instance Methods

add_step_from_args(args, options = {}, &block) click to toggle source
# File lib/rung/definition/steps_dsl.rb, line 31
def add_step_from_args(args, options = {}, &block)
  action, action_options = extract_action_and_options!(args)
  add_generic_step action, **options, **action_options, &block
end
calculate_block_nested_steps(&block) click to toggle source
# File lib/rung/definition/steps_dsl.rb, line 51
def calculate_block_nested_steps(&block)
  with_new_steps_definition do
    instance_exec(&block)
    steps_definition
  end
end
extract_action_and_options!(args) click to toggle source
# File lib/rung/definition/steps_dsl.rb, line 36
def extract_action_and_options!(args)
  options = args.last.is_a?(::Hash) ? args.pop : {}
  [args.first, options]
end
step_from_definition(action, options, &block) click to toggle source
# File lib/rung/definition/steps_dsl.rb, line 41
def step_from_definition(action, options, &block)
  if action && block
    NestedStep.new(action, calculate_block_nested_steps(&block), options)
  elsif block
    Step.new(block, **options, from_block: true)
  else
    Step.new(action, options)
  end
end
with_new_steps_definition() { || ... } click to toggle source
# File lib/rung/definition/steps_dsl.rb, line 58
def with_new_steps_definition
  old_steps_definition = @steps_definition
  @steps_definition = []
  yield
ensure
  @steps_definition = old_steps_definition
end