class Lite::Command::Procedure

Attributes

exit_on_failure[RW]

Public Instance Methods

execute() click to toggle source
# File lib/lite/command/procedure.rb, line 11
def execute
  steps.each_with_object([]).with_index do |(command, results), i|
    command.call

    if command.respond_to?(:errors) && command.failure?
      failed_steps << failed_step(i, command)
      merge_errors!(command) if respond_to?(:errors)
      break results if exit_on_failure?
    else
      results << command.result
    end
  end
end
exit_on_failure?() click to toggle source
# File lib/lite/command/procedure.rb, line 25
def exit_on_failure?
  @exit_on_failure ||= false
end
failed_steps() click to toggle source
# File lib/lite/command/procedure.rb, line 29
def failed_steps
  @failed_steps ||= []
end
steps() click to toggle source
# File lib/lite/command/procedure.rb, line 33
def steps
  @steps ||= @args.flatten
end

Private Instance Methods

failed_step(index, command) click to toggle source
# File lib/lite/command/procedure.rb, line 39
def failed_step(index, command)
  {
    index: index,
    step: index + 1,
    name: command.class.name,
    args: command.args,
    errors: command&.errors&.full_messages
  }
end