Class: Opera::Operation::Executor

Inherits:
Object
  • Object
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

#operationObject (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_conditionObject



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

#configObject



61
62
63
# File 'lib/opera/operation/executor.rb', line 61

def config
  operation.config
end

#contextObject



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

Returns:

  • (Boolean)


65
66
67
# File 'lib/opera/operation/executor.rb', line 65

def production_mode?
  config.mode == Config::PRODUCTION_MODE
end

#reporterObject



73
74
75
# File 'lib/opera/operation/executor.rb', line 73

def reporter
  config.reporter
end

#resultObject

rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity



57
58
59
# File 'lib/opera/operation/executor.rb', line 57

def result
  operation.result
end