Class: Opera::Operation::Executor
- Inherits:
-
Object
- Object
- Opera::Operation::Executor
show all
- Defined in:
- lib/opera/operation/executor.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
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
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
90
91
92
|
# File 'lib/opera/operation/executor.rb', line 90
def add_instruction_output(instruction, output = {})
context[:"#{instruction[:method]}_output"] = output
end
|
#break_condition ⇒ Object
86
87
88
|
# File 'lib/opera/operation/executor.rb', line 86
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
70
71
72
|
# File 'lib/opera/operation/executor.rb', line 70
def config
operation.config
end
|
#context ⇒ Object
78
79
80
|
# File 'lib/opera/operation/executor.rb', line 78
def context
operation.context
end
|
#evaluate_instruction(instruction) ⇒ Object
rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity
#evaluate_instructions(instructions = []) ⇒ Object
22
23
24
25
26
27
|
# File 'lib/opera/operation/executor.rb', line 22
def evaluate_instructions(instructions = [])
instructions.each do |instruction|
evaluate_instruction(instruction)
break if break_condition
end
end
|
#execute_step(instruction) ⇒ Object
Executes the operation method named in the instruction, instruments it, and records the execution. This is the shared primitive that all executors use to invoke a step method without mutating the instruction hash.
32
33
34
35
36
37
38
39
|
# File 'lib/opera/operation/executor.rb', line 32
def execute_step(instruction)
method = instruction[:method]
Instrumentation.new(operation).instrument(name: "##{method}", level: :step) do
result.add_execution(method) unless production_mode?
operation.send(method)
end
end
|
#production_mode? ⇒ Boolean
74
75
76
|
# File 'lib/opera/operation/executor.rb', line 74
def production_mode?
config.mode == Config::PRODUCTION_MODE
end
|
#reporter ⇒ Object
82
83
84
|
# File 'lib/opera/operation/executor.rb', line 82
def reporter
config.reporter
end
|
#result ⇒ Object
rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity
66
67
68
|
# File 'lib/opera/operation/executor.rb', line 66
def result
operation.result
end
|