Module: Dunlop::WorkflowInstanceModel::WorkflowStepHandling
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/dunlop/workflow_instance_model/workflow_step_handling.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#setup_workflow_steps ⇒ Object
Instantiate workflow_step instances if not already present.
-
#trigger_if_all_workflow_steps_in_batch_are_in_final_state(workflow_step) ⇒ Object
This method checks if all workflow steps in the same steps are in a final state and triggers a hook if this is the case.
-
#workflow_instance ⇒ Object
Make sure in all views a call to workflow_instance and workflow_instance_id can be made.
-
#workflow_instance_id ⇒ Object
Make sure in all views a call to workflow_instance and workflow_instance_id can be made.
- #workflow_step_completed!(workflow_step) ⇒ Object
- #workflow_step_overdue!(workflow_step) ⇒ Object
- #workflow_step_processing!(workflow_step) ⇒ Object
- #workflow_step_rejected!(workflow_step) ⇒ Object
- #workflow_steps ⇒ Object
Instance Method Details
#setup_workflow_steps ⇒ Object
Instantiate workflow_step instances if not already present
19 20 21 22 23 24 25 |
# File 'app/models/dunlop/workflow_instance_model/workflow_step_handling.rb', line 19 def setup_workflow_steps return if self.class == WorkflowInstance # can only be done on scenario class self.class.scenario_workflow_step_names.each do |step_name| step_class = "#{step_name.to_s.classify}::#{scenario_name.classify}" public_send "build_#{step_name}", sti_type: step_class unless public_send(step_name) end end |
#trigger_if_all_workflow_steps_in_batch_are_in_final_state(workflow_step) ⇒ Object
This method checks if all workflow steps in the same steps are in a final state and triggers a hook if this is the case
53 54 55 56 57 58 59 60 |
# File 'app/models/dunlop/workflow_instance_model/workflow_step_handling.rb', line 53 def trigger_if_all_workflow_steps_in_batch_are_in_final_state(workflow_step) return unless workflow_instance_batch.present? batch_states = workflow_step.workflow_steps_in_batch_scope.uniq.pluck(:state) #return unless workflow_step.changes[:state].present? if batch_states.any? and (batch_states - workflow_step.class.final_states).empty? workflow_step.all_of_batch_are_in_final_state(workflow_instance_batch) end end |
#workflow_instance ⇒ Object
Make sure in all views a call to workflow_instance and workflow_instance_id can be made
9 10 11 |
# File 'app/models/dunlop/workflow_instance_model/workflow_step_handling.rb', line 9 def workflow_instance self #duh end |
#workflow_instance_id ⇒ Object
Make sure in all views a call to workflow_instance and workflow_instance_id can be made
14 15 16 |
# File 'app/models/dunlop/workflow_instance_model/workflow_step_handling.rb', line 14 def workflow_instance_id id end |
#workflow_step_completed!(workflow_step) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'app/models/dunlop/workflow_instance_model/workflow_step_handling.rb', line 33 def workflow_step_completed!(workflow_step) if workflow_steps.map(&:rejected?).any? any_rejected else workflow_steps.map(&:completed?).all? ? all_completed : activate end trigger_if_all_workflow_steps_in_batch_are_in_final_state(workflow_step) end |
#workflow_step_overdue!(workflow_step) ⇒ Object
47 48 49 |
# File 'app/models/dunlop/workflow_instance_model/workflow_step_handling.rb', line 47 def workflow_step_overdue!(workflow_step) overdue unless final_states.include?(state) end |
#workflow_step_processing!(workflow_step) ⇒ Object
27 28 29 30 31 |
# File 'app/models/dunlop/workflow_instance_model/workflow_step_handling.rb', line 27 def workflow_step_processing!(workflow_step) unless workflow_steps.map(&:rejected?).any? activate end end |
#workflow_step_rejected!(workflow_step) ⇒ Object
42 43 44 45 |
# File 'app/models/dunlop/workflow_instance_model/workflow_step_handling.rb', line 42 def workflow_step_rejected!(workflow_step) any_rejected trigger_if_all_workflow_steps_in_batch_are_in_final_state(workflow_step) end |
#workflow_steps ⇒ Object
4 5 6 |
# File 'app/models/dunlop/workflow_instance_model/workflow_step_handling.rb', line 4 def workflow_steps self.class.scenario_workflow_step_names.map{|workflow_step| public_send workflow_step }.compact end |