Class: RailsWorkflow::ProcessBuilder

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

Overview

DefaultBuilder

Process Builder is used to build new process. All process building logic should be gathered here. It defines how process is build using template (for example it can used to gather some additional information from system - for example some information from existing processes or it can handle hierarchical processes logic for parent / child processes).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, context) ⇒ ProcessBuilder

Returns a new instance of ProcessBuilder.



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

def initialize(template, context)
  @template = template
  @context = context
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



12
13
14
# File 'lib/rails_workflow/process_builder.rb', line 12

def context
  @context
end

#templateObject

Returns the value of attribute template.



12
13
14
# File 'lib/rails_workflow/process_builder.rb', line 12

def template
  @template
end

Instance Method Details

#build_independent_operations(process) ⇒ Object

Independent operations is template operations that have no dependencies from any other operations



33
34
35
36
37
# File 'lib/rails_workflow/process_builder.rb', line 33

def build_independent_operations(process)
  independent_operations.each do |operation_template|
    build_operation process, operation_template
  end
end

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



39
40
41
42
43
# File 'lib/rails_workflow/process_builder.rb', line 39

def build_operation(process, template, completed_dependencies = [])
  operation_builder.new(
    process, template, completed_dependencies
  ).create_operation
end

#configObject



49
50
51
# File 'lib/rails_workflow/process_builder.rb', line 49

def config
  RailsWorkflow.config
end

#create_process!Object



21
22
23
24
25
26
27
28
29
# File 'lib/rails_workflow/process_builder.rb', line 21

def create_process!
  process = process_class.create(template: template)

  process.update_attributes(title: title, status: Process::NOT_STARTED)
  process.create_context(data: context, parent: process)

  build_independent_operations process
  process
end

#error_builderObject



45
46
47
# File 'lib/rails_workflow/process_builder.rb', line 45

def error_builder
  config.error_builder
end

#operation_builderObject



53
54
55
# File 'lib/rails_workflow/process_builder.rb', line 53

def operation_builder
  config.operation_builder
end