Class: RailsWorkflow::OperationBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_workflow/operation_builder.rb

Overview

Operation builder which creates new operaitons including their context, child processes etc… s

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(process, template, completed_dependencies = []) ⇒ OperationBuilder

Returns a new instance of OperationBuilder.



10
11
12
13
14
# File 'lib/rails_workflow/operation_builder.rb', line 10

def initialize(process, template, completed_dependencies = [])
  @process = process
  @template = template
  @completed_dependencies = completed_dependencies
end

Instance Attribute Details

#completed_dependenciesObject

Returns the value of attribute completed_dependencies.



7
8
9
# File 'lib/rails_workflow/operation_builder.rb', line 7

def completed_dependencies
  @completed_dependencies
end

#processObject

Returns the value of attribute process.



7
8
9
# File 'lib/rails_workflow/operation_builder.rb', line 7

def process
  @process
end

#templateObject

Returns the value of attribute template.



7
8
9
# File 'lib/rails_workflow/operation_builder.rb', line 7

def template
  @template
end

Instance Method Details

#after_operation_create(operation) ⇒ Object



35
36
37
38
# File 'lib/rails_workflow/operation_builder.rb', line 35

def after_operation_create(operation)
  return unless template.respond_to?(:after_operation_create)
  template.after_operation_create(operation)
end

#create_operationObject



16
17
18
19
20
# File 'lib/rails_workflow/operation_builder.rb', line 16

def create_operation
  create_operation!.tap { |operation| process.operations << operation }
rescue => exception
  handle_exception(exception)
end

#create_operation!Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rails_workflow/operation_builder.rb', line 22

def create_operation!
  operation = operation_class.create(prepared_attributes) do |new_operation|
    new_operation.context = build_context(
      new_operation, completed_dependencies
    )

    after_operation_create(new_operation)
  end

  build_child_process(operation)
  operation
end

#prepared_dependenciesObject



40
41
42
43
44
45
46
47
# File 'lib/rails_workflow/operation_builder.rb', line 40

def prepared_dependencies
  completed_dependencies.map do |dep|
    {
      operation_id: dep.id,
      status: dep.status
    }
  end
end