Module: RailsWorkflow::OperationTemplates::DefaultBuilder

Extended by:
ActiveSupport::Concern
Included in:
RailsWorkflow::OperationTemplate
Defined in:
app/concerns/rails_workflow/operation_templates/default_builder.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#build_operation(operation) ⇒ Object



6
7
8
# File 'app/concerns/rails_workflow/operation_templates/default_builder.rb', line 6

def build_operation operation
  #for customization
end

#build_operation!(process, completed_dependencies = []) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/concerns/rails_workflow/operation_templates/default_builder.rb', line 10

def build_operation! process, completed_dependencies = []

  attrs = attributes.
      with_indifferent_access.
      slice(:title, :async, :is_background).
      merge({
                template: self,
                process: process,
                status: Operation::NOT_STARTED,
                manager: process.manager
            })


  attrs[:dependencies] = completed_dependencies.map { |dep|
    {
        operation_id: dep.id,
        status: dep.status
    }
  }


  operation = operation_class.create(attrs) do |op|
    op.context = RailsWorkflow::OperationTemplate.build_context! op, completed_dependencies

    build_operation op
  end

  if child_process.present?
    operation.child_process = RailsWorkflow::ProcessManager.
        build_process(
            child_process.id,
            operation.context.data
        )
  end
  operation

end