Module: Dunlop::WorkflowStepModel
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/dunlop/workflow_step_model.rb
Defined Under Namespace
Modules: ClassMethods, NotesHandling, StateMachine
Instance Method Summary collapse
-
#all_of_batch_are_in_final_state(workflow_instance_batch) ⇒ Object
This method will be triggered if all the workflow intances in the same batch are in a final state (completed, rejected).
-
#collection? ⇒ Boolean
TODO: should this be part of the record_collection gem?.
-
#reset! ⇒ Object
Reset the attributes defined on the collection to the default value of a new record and set the state back to pending.
-
#workflow_steps_in_batch_scope(workflow_step = process_name) ⇒ Object
returns the scope for all the workflow steps in the same batch.
Methods included from AttributeChangesTracking
#last_changed, #update_last_attribute_changed_at
Methods included from StateMachine
#after_transition_hook, #before_transition_hook, #complete!, #is_overdue!, #process!, #reject!
Instance Method Details
#all_of_batch_are_in_final_state(workflow_instance_batch) ⇒ Object
This method will be triggered if all the workflow intances in the same batch are in a final state (completed, rejected). To use this functionality, implment in the appropriate class
45 46 |
# File 'app/models/dunlop/workflow_step_model.rb', line 45 def all_of_batch_are_in_final_state(workflow_instance_batch) end |
#collection? ⇒ Boolean
TODO: should this be part of the record_collection gem?
15 16 17 |
# File 'app/models/dunlop/workflow_step_model.rb', line 15 def collection? false end |
#reset! ⇒ Object
Reset the attributes defined on the collection to the default value of a new record and set the state back to pending
21 22 23 24 25 26 27 28 |
# File 'app/models/dunlop/workflow_step_model.rb', line 21 def reset! new_record = self.class.new collection_class.attributes.except('notes').each do |attr, clean_value| self[attr] = new_record[attr] end self.notes = "[RESET]" pending end |
#workflow_steps_in_batch_scope(workflow_step = process_name) ⇒ Object
returns the scope for all the workflow steps in the same batch. If the record has no batch an empty scope is returned.
record = workflow_instance.contractor_service_window1_execution
record.workflow_steps_in_batch_scope #=> All the ContractorServiceWindow1Execution workflow step records for the batch
record.workflow_steps_in_batch_scope(:owner_initialization) #=> All the OwnerInitialization workflow step records for the batch
35 36 37 38 39 40 |
# File 'app/models/dunlop/workflow_step_model.rb', line 35 def workflow_steps_in_batch_scope(workflow_step = process_name) klass = workflow_step.to_s.classify.constantize batch_id = workflow_instance.workflow_instance_batch_id return klass.none unless batch_id.present? klass.joins(:workflow_instance).where(workflow_instances: {workflow_instance_batch_id: batch_id}) end |