Module: Accountable::Accountor::States::StateMachineTraits

Defined in:
lib/accountable/accountor/states/state_machine_traits.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/accountable/accountor/states/state_machine_traits.rb', line 4

def self.included( base )
  base.class_eval do
    include StateMachineInstanceMethods

    state_machine :status, :initial => :passive do
      state :passive, :active, :suspended

      event :activate do
        transition [:passive] => :active
      end
      after_transition :on => :active, :do => :do_activate

      event :suspend do
        transition  [:passive, :active] => :suspended
      end
      after_transition :on => :active, :do => :do_suspend
      
      event :unsuspend do
        transition [:suspended] => :active
      end
    end
  end
end