Class: RailsWorkflow::ProcessRunner
- Inherits:
-
Object
- Object
- RailsWorkflow::ProcessRunner
- Defined in:
- lib/rails_workflow/process_runner.rb
Overview
ProcessRunner
This module contains logic of process start, stop, cancel etc.
Instance Attribute Summary collapse
-
#process ⇒ Object
readonly
Returns the value of attribute process.
Instance Method Summary collapse
-
#completable? ⇒ Boolean
Process can be completed if all sync operations is complete.
-
#complete ⇒ Object
TODO: change to try_complete.
- #complete_parent_operation ⇒ Object
-
#initialize(process) ⇒ ProcessRunner
constructor
A new instance of ProcessRunner.
- #operation_completed(operation) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(process) ⇒ ProcessRunner
Returns a new instance of ProcessRunner.
15 16 17 |
# File 'lib/rails_workflow/process_runner.rb', line 15 def initialize(process) @process = process end |
Instance Attribute Details
#process ⇒ Object (readonly)
Returns the value of attribute process.
10 11 12 |
# File 'lib/rails_workflow/process_runner.rb', line 10 def process @process end |
Instance Method Details
#completable? ⇒ Boolean
Process can be completed if all sync operations is complete
28 29 30 |
# File 'lib/rails_workflow/process_runner.rb', line 28 def completable? uncompleted? && workflow_errors.unresolved.size.zero? end |
#complete ⇒ Object
TODO: change to try_complete
37 38 39 40 41 42 |
# File 'lib/rails_workflow/process_runner.rb', line 37 def complete return unless completable? process.complete complete_parent_operation end |
#complete_parent_operation ⇒ Object
32 33 34 |
# File 'lib/rails_workflow/process_runner.rb', line 32 def complete_parent_operation parent_operation.complete if parent_operation.present? end |
#operation_completed(operation) ⇒ Object
44 45 46 47 |
# File 'lib/rails_workflow/process_runner.rb', line 44 def operation_completed(operation) build_new_operations(operation) complete end |
#start ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/rails_workflow/process_runner.rb', line 19 def start return unless can_start? process.update_attribute(:status, Status::IN_PROGRESS) # TODO: replace with OperationRunner operation_runner.start(operations.where(status: Status::NOT_STARTED)) end |