Module: Dunlop::WorkflowStepModel::StateMachine

Extended by:
ActiveSupport::Concern
Included in:
Dunlop::WorkflowStepModel
Defined in:
app/models/dunlop/workflow_step_model/state_machine.rb

Instance Method Summary collapse

Instance Method Details

#after_transition_hook(transition) ⇒ Object



38
39
# File 'app/models/dunlop/workflow_step_model/state_machine.rb', line 38

def after_transition_hook(transition)
end

#before_transition_hook(transition) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/dunlop/workflow_step_model/state_machine.rb', line 23

def before_transition_hook(transition)
  return unless self.class.columns_hash['notes'].try(:type) == :text
  changes.except('notes').each do |attr, (from, to)|
    case self.class.columns_hash[attr].type
    when :boolean
      append_note "[CHECK_CHANGE] #{self.class.human_attribute_name(attr)} changed to #{to ? 'yes' : 'no'}"
    else
      attribute_name, value = get_attribute_name_and_value_for(attr, to)
      value = "[EMPTY]" if value == '' or value.nil?
      append_note "[CHANGE] #{attribute_name} changed to #{value}"
    end
  end
  append_note "[STATE_CHANGE] #{transition.from} => #{transition.to}" if transition.from != transition.to
end

#complete!Object



47
48
49
50
51
# File 'app/models/dunlop/workflow_step_model/state_machine.rb', line 47

def complete!
  return save if completed?
  completed
  workflow_instance.workflow_step_completed!(self)
end

#is_overdue!Object



59
60
61
62
63
# File 'app/models/dunlop/workflow_step_model/state_machine.rb', line 59

def is_overdue!
  return save if overdue?
  overdue
  workflow_instance.workflow_step_overdue!(self)
end

#process!Object



41
42
43
44
45
# File 'app/models/dunlop/workflow_step_model/state_machine.rb', line 41

def process!
  return save if processing?
  processing
  workflow_instance.workflow_step_processing!(self)
end

#reject!Object



53
54
55
56
57
# File 'app/models/dunlop/workflow_step_model/state_machine.rb', line 53

def reject!
  return save if rejected?
  rejected
  workflow_instance.workflow_step_rejected!(self)
end