Class: RailsWorkflow::ProcessManager

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

Overview

ProcessManager should be used to build and start processes. It is top level hierarchy class that also can be used to build enhancements. For example they can be used to implement processes communications.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(process = nil, template_id: nil, context: nil) ⇒ ProcessManager

Returns a new instance of ProcessManager.



19
20
21
22
23
# File 'lib/rails_workflow/process_manager.rb', line 19

def initialize(process = nil, template_id: nil, context: nil)
  @process = process
  @template = ProcessTemplate.find(template_id) if template_id
  @context = context
end

Instance Attribute Details

#context ⇒ Object

Returns the value of attribute context.



9
10
11
# File 'lib/rails_workflow/process_manager.rb', line 9

def context
  @context
end

#process ⇒ Object

Returns the value of attribute process.



9
10
11
# File 'lib/rails_workflow/process_manager.rb', line 9

def process
  @process
end

#template ⇒ Object

Returns the value of attribute template.



9
10
11
# File 'lib/rails_workflow/process_manager.rb', line 9

def template
  @template
end

Class Method Details

.create_process(template_id, context) ⇒ Object



14
15
16
# File 'lib/rails_workflow/process_manager.rb', line 14

def create_process(template_id, context)
  new(template_id: template_id, context: context).create_process
end

.start_process(template_id, context) ⇒ Object



29
30
31
32
33
# File 'lib/rails_workflow/process_manager.rb', line 29

def self.start_process(template_id, context)
  process = create_process template_id, context
  new(process).start_process
  process
end

Instance Method Details

#complete_process ⇒ Object



46
47
48
# File 'lib/rails_workflow/process_manager.rb', line 46

def complete_process
  process_runner.complete
end

#config ⇒ Object



62
63
64
# File 'lib/rails_workflow/process_manager.rb', line 62

def config
  RailsWorkflow.config
end

#create_process ⇒ Object



25
26
27
# File 'lib/rails_workflow/process_manager.rb', line 25

def create_process
  self.process = process_builder.new(template, context).create_process!
end

#error_builder ⇒ Object



50
51
52
# File 'lib/rails_workflow/process_manager.rb', line 50

def error_builder
  config.error_builder
end

#process_builder ⇒ Object



54
55
56
# File 'lib/rails_workflow/process_manager.rb', line 54

def process_builder
  config.process_builder
end

#process_runner ⇒ Object



58
59
60
# File 'lib/rails_workflow/process_manager.rb', line 58

def process_runner
  @process_runner ||= config.process_runner.new(process)
end

#start_process ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/rails_workflow/process_manager.rb', line 35

def start_process
  process_runner.start
rescue => exception
  error_builder.handle(
    exception,
    parent: process,
    target: :process_manager,
    method: :start_process
  )
end