Module: Dunlop::WorkflowInstanceModel::ClassMethods
- Defined in:
- app/models/dunlop/workflow_instance_model.rb
Instance Attribute Summary collapse
-
#scenario_names ⇒ Object
readonly
Returns the value of attribute scenario_names.
Instance Method Summary collapse
- #activate_dunlop! ⇒ Object
-
#add_missing_workflow_steps ⇒ Object
Mainly used in development stage from console or as a post migration step.
- #available_bucket_names ⇒ Object
- #batch_class ⇒ Object
-
#including_relations ⇒ Object
Add include statements to the scope for including workflow_instance displays for the index action.
- #scenario_classes ⇒ Object
- #scope_for(user, options = {}) ⇒ Object
- #setup_scenarios(scenario_names) ⇒ Object
Instance Attribute Details
#scenario_names ⇒ Object (readonly)
Returns the value of attribute scenario_names.
21 22 23 |
# File 'app/models/dunlop/workflow_instance_model.rb', line 21 def scenario_names @scenario_names end |
Instance Method Details
#activate_dunlop! ⇒ Object
26 27 28 29 30 31 32 |
# File 'app/models/dunlop/workflow_instance_model.rb', line 26 def activate_dunlop! possible_workflow_step_names.each do |step_name| has_one step_name, dependent: :destroy #, inverse_of: :workflow_instance end #raise "No scenarios defined!, define scenarios using: setup_scenarios :scenario1, :other_scenario" unless @scenario_names #scenario_classes # this will raise if not all of them can be constantized end |
#add_missing_workflow_steps ⇒ Object
Mainly used in development stage from console or as a post migration step. This adds workflow_steps that should be there based on the configuration but are missing in the database
61 62 63 64 65 66 |
# File 'app/models/dunlop/workflow_instance_model.rb', line 61 def add_missing_workflow_steps includes(*possible_workflow_step_names).find_each do |workflow_instance| workflow_instance.setup_workflow_steps workflow_instance.save end end |
#available_bucket_names ⇒ Object
50 51 52 |
# File 'app/models/dunlop/workflow_instance_model.rb', line 50 def available_bucket_names uniq.pluck(:bucket).map(&:presence).compact end |
#batch_class ⇒ Object
54 55 56 |
# File 'app/models/dunlop/workflow_instance_model.rb', line 54 def batch_class @batch_class ||= name.sub('WorkflowInstance', 'WorkflowInstanceBatch').safe_constantize end |
#including_relations ⇒ Object
Add include statements to the scope for including workflow_instance displays for the index action
36 37 38 |
# File 'app/models/dunlop/workflow_instance_model.rb', line 36 def including_relations includes(*scenario_workflow_step_names, :workflow_instance_batch) end |
#scenario_classes ⇒ Object
40 41 42 |
# File 'app/models/dunlop/workflow_instance_model.rb', line 40 def scenario_classes scenario_names.map{|scenario_name| "WorkflowInstance::#{scenario_name.to_s.classify}".constantize } end |
#scope_for(user, options = {}) ⇒ Object
44 45 46 47 48 |
# File 'app/models/dunlop/workflow_instance_model.rb', line 44 def scope_for(user, = {}) scope = [:all] ? all : ([:archived] ? archived : active) #scope = scope.where(service_provider_id: user.service_provider_id) if user.service_provider_id.present? scope end |
#setup_scenarios(scenario_names) ⇒ Object
22 23 24 |
# File 'app/models/dunlop/workflow_instance_model.rb', line 22 def setup_scenarios(scenario_names) @scenario_names = scenario_names end |