Class: Lite::Command::Procedure

Inherits:
Complex
  • Object
show all
Includes:
Extensions::Errors
Defined in:
lib/lite/command/procedure.rb

Instance Attribute Summary collapse

Attributes inherited from Complex

#args, #result

Instance Method Summary collapse

Methods included from Extensions::Errors

#errored?, #errors, #fail!, #failure?, included, #merge_errors!, #merge_exception!, #result!, #status, #success?, #validate!

Methods inherited from Complex

call, #call, #called?, execute, #initialize, #recall!

Constructor Details

This class inherits a constructor from Lite::Command::Complex

Instance Attribute Details

#exit_on_failureObject

Returns the value of attribute exit_on_failure.



9
10
11
# File 'lib/lite/command/procedure.rb', line 9

def exit_on_failure
  @exit_on_failure
end

Instance Method Details

#executeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# 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?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/lite/command/procedure.rb', line 25

def exit_on_failure?
  @exit_on_failure ||= false
end

#failed_stepsObject



29
30
31
# File 'lib/lite/command/procedure.rb', line 29

def failed_steps
  @failed_steps ||= []
end

#stepsObject



33
34
35
# File 'lib/lite/command/procedure.rb', line 33

def steps
  @steps ||= @args.flatten
end