Class: Opera::Operation::Executor
- Inherits:
-
Object
- Object
- Opera::Operation::Executor
- Defined in:
- lib/opera/operation/executor.rb
Direct Known Subclasses
Instructions::Executors::Benchmark, Instructions::Executors::FinishIf, Instructions::Executors::Operation, Instructions::Executors::Operations, Instructions::Executors::Step, Instructions::Executors::Success, Instructions::Executors::Transaction, Instructions::Executors::Validate
Instance Attribute Summary collapse
-
#operation ⇒ Object
readonly
Returns the value of attribute operation.
Instance Method Summary collapse
- #add_instruction_output(instruction, output = {}) ⇒ Object
- #break_condition ⇒ Object
- #call(instruction) ⇒ Object
- #config ⇒ Object
- #context ⇒ Object
-
#evaluate_instruction(instruction) ⇒ Object
rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity.
- #evaluate_instructions(instructions = []) ⇒ Object
-
#initialize(operation) ⇒ Executor
constructor
A new instance of Executor.
- #production_mode? ⇒ Boolean
- #reporter ⇒ Object
-
#result ⇒ Object
rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity.
Constructor Details
#initialize(operation) ⇒ Executor
Returns a new instance of Executor.
8 9 10 |
# File 'lib/opera/operation/executor.rb', line 8 def initialize(operation) @operation = operation end |
Instance Attribute Details
#operation ⇒ Object (readonly)
Returns the value of attribute operation.
6 7 8 |
# File 'lib/opera/operation/executor.rb', line 6 def operation @operation end |
Instance Method Details
#add_instruction_output(instruction, output = {}) ⇒ Object
81 82 83 |
# File 'lib/opera/operation/executor.rb', line 81 def add_instruction_output(instruction, output = {}) context["#{instruction[:method]}_output".to_sym] = output end |
#break_condition ⇒ Object
77 78 79 |
# File 'lib/opera/operation/executor.rb', line 77 def break_condition operation.finished? || result.failure? end |
#call(instruction) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/opera/operation/executor.rb', line 12 def call(instruction) instructions = instruction[:instructions] if instructions evaluate_instructions(instructions) else evaluate_instruction(instruction) end end |
#config ⇒ Object
61 62 63 |
# File 'lib/opera/operation/executor.rb', line 61 def config operation.config end |
#context ⇒ Object
69 70 71 |
# File 'lib/opera/operation/executor.rb', line 69 def context operation.context end |
#evaluate_instruction(instruction) ⇒ Object
rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/opera/operation/executor.rb', line 33 def evaluate_instruction(instruction) case instruction[:kind] when :step Instructions::Executors::Step.new(operation).call(instruction) when :operation Instructions::Executors::Operation.new(operation).call(instruction) when :operations Instructions::Executors::Operations.new(operation).call(instruction) when :success Instructions::Executors::Success.new(operation).call(instruction) when :validate Instructions::Executors::Validate.new(operation).call(instruction) when :transaction Instructions::Executors::Transaction.new(operation).call(instruction) when :benchmark Instructions::Executors::Benchmark.new(operation).call(instruction) when :finish_if Instructions::Executors::FinishIf.new(operation).call(instruction) else raise(UnknownInstructionError, "Unknown instruction #{instruction[:kind]}") end end |
#evaluate_instructions(instructions = []) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/opera/operation/executor.rb', line 22 def evaluate_instructions(instructions = []) instruction_copy = Marshal.load(Marshal.dump(instructions)) while instruction_copy.any? instruction = instruction_copy.shift evaluate_instruction(instruction) break if break_condition end end |
#production_mode? ⇒ Boolean
65 66 67 |
# File 'lib/opera/operation/executor.rb', line 65 def production_mode? config.mode == Config::PRODUCTION_MODE end |
#reporter ⇒ Object
73 74 75 |
# File 'lib/opera/operation/executor.rb', line 73 def reporter config.reporter end |
#result ⇒ Object
rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity
57 58 59 |
# File 'lib/opera/operation/executor.rb', line 57 def result operation.result end |