Class: Nayati::WorkflowRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/nayati/workflow_runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(workflow, context) ⇒ WorkflowRunner

Returns a new instance of WorkflowRunner.



3
4
5
6
7
# File 'lib/nayati/workflow_runner.rb', line 3

def initialize(workflow, context)
  @workflow = workflow
  @context = context
  @result_obj = workflow.result_obj
end

Instance Method Details

#runObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/nayati/workflow_runner.rb', line 9

def run
  operation_to_perform = @workflow.initial_operation
  operations_performed = []

  while !operation_to_perform.nil? && !operations_performed.include?(operation_to_perform.name) # && safety_count > 0
    operation_klass_instance = operation_to_perform.build_implementer(@context, @result_obj)
    if operation_klass_instance.to_abandon?
      operation_klass_instance.perform_abandonment
      break
    end

    operations_performed << operation_to_perform.name

    if operation_klass_instance.to_fail?
      operation_klass_instance.perform_failure
      operation_to_perform = operation_to_perform.after_failure_operation
    else
      operation_klass_instance.perform
      operation_to_perform = operation_to_perform.after_success_operation
    end
  end

  @result_obj
end