Module: RailsWorkflow::Processes::DefaultRunner
- Extended by:
- ActiveSupport::Concern
- Included in:
- RailsWorkflow::Process
- Defined in:
- app/concerns/rails_workflow/processes/default_runner.rb
Overview
This module contains methods for starting/completing process, operations etc.
Instance Method Summary (collapse)
-
- (boolean) can_complete?
Checks if process can be completed.
-
- (boolean) can_start?
Checks if current process can start.
-
- (Object) complete
Completing process.
-
- (Object) incompleted_operations
Returns set or operation that not yet completed.
-
- (Object) operation_complete(operation)
If operation is completed process is responsible for building new operations.
-
- (Object) operation_exception
Processing operation exceptions.
-
- (Object) start
Starting process and all independent operations that exists in process.
Instance Method Details
- (boolean) can_complete?
Checks if process can be completed. Process can be completed if it has IN_PROGRESS or NOT_STARTED status and all it's operaitons completed and all it's errors are resolved.
30 31 32 33 34 35 36 37 |
# File 'app/concerns/rails_workflow/processes/default_runner.rb', line 30 def can_complete? if incomplete_statuses.include? status incompleted_operations.size == 0 && workflow_errors.unresolved.size == 0 else false end end |
- (boolean) can_start?
Checks if current process can start.
10 11 12 |
# File 'app/concerns/rails_workflow/processes/default_runner.rb', line 10 def can_start? operations.size > 0 end |
- (Object) complete
Completing process. If current process has parent operation - tries to complete it.
53 54 55 56 57 58 59 |
# File 'app/concerns/rails_workflow/processes/default_runner.rb', line 53 def complete self.status = self.class::DONE if can_complete? save if parent_operation.present? parent_operation.complete end end |
- (Object) incompleted_operations
Returns set or operation that not yet completed. Completed operation has DONE, SKIPPED, CANCELED, etc statuses
41 42 43 |
# File 'app/concerns/rails_workflow/processes/default_runner.rb', line 41 def incompleted_operations operations.reject{|operation| operation.completed? } end |
- (Object) operation_complete(operation)
If operation is completed process is responsible for building new operations. We need to calculate operations, depends on completed one and detect ones we can build.
48 49 50 |
# File 'app/concerns/rails_workflow/processes/default_runner.rb', line 48 def operation_complete operation build_dependencies operation end |
- (Object) operation_exception
Processing operation exceptions. By default just set ERROR status for process.
23 24 25 |
# File 'app/concerns/rails_workflow/processes/default_runner.rb', line 23 def operation_exception self.status = self.class::ERROR end |
- (Object) start
Starting process and all independent operations that exists in process.
15 16 17 18 19 20 |
# File 'app/concerns/rails_workflow/processes/default_runner.rb', line 15 def start if can_start? update_attribute(:status, self.class::IN_PROGRESS) self.operations.where(status: RailsWorkflow::Operation::NOT_STARTED).map(&:start) end end |