Module: Dunlop::WorkflowInstanceModel::StateMachineHandling

Extended by:
ActiveSupport::Concern
Defined in:
app/models/dunlop/workflow_instance_model/state_machine_handling.rb

Instance Method Summary collapse

Instance Method Details

#after_transition_hook(transition) ⇒ Object

Gets triggered after a transition



24
25
# File 'app/models/dunlop/workflow_instance_model/state_machine_handling.rb', line 24

def after_transition_hook(transition)
end

#before_transition_hook(transition) ⇒ Object

Gets triggered before a transition



28
29
# File 'app/models/dunlop/workflow_instance_model/state_machine_handling.rb', line 28

def before_transition_hook(transition)
end

#final_statesObject



3
4
5
# File 'app/models/dunlop/workflow_instance_model/state_machine_handling.rb', line 3

def final_states
  %w[all_completed any_rejected]
end

#set_state_based_on_subprocess_statesObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/dunlop/workflow_instance_model/state_machine_handling.rb', line 31

def set_state_based_on_subprocess_states
  states = workflow_steps.compact.map(&:state).compact.uniq
  if states.uniq == ['completed']
    self.state = 'all_completed'
  elsif states.include? 'rejected'
    self.state = 'any_rejected'
  elsif states.include? 'overdue'
    self.state = 'overdue'
  elsif (states & %w[processing rejected completed]).any?
    self.state = 'active'
  elsif is_planned?
    self.state = 'planned'
  else
    self.state = 'unplanned'
  end
  true # do not halt propagation
end