Module: SuperState::CommonStates

Defined in:
lib/super_state/common_states.rb

Class Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/super_state/common_states.rb', line 5

def self.included(klass)
  klass.class_eval do
    include SuperState
  
    super_state :pending, :initial => true
    super_state :processing
    super_state :completed
    super_state :failed
  
    super_state_group :outstanding, ["pending", "processing"]
  
    # first part of a two stage transition
    # eg.
    #   def process
    #     start_processing!
    #       do_the_stuff
    #     complete_processing!
    #   end
    #
    state_transition :start_processing, :pending => :processing
  
    # second part of a two stage transition
    state_transition :complete_processing, :processing => :completed
  
    # transition direct from pending to complete
    state_transition :complete, :pending => :completed
  
    # failed to process
    state_transition :fail, :processing => :failed
  
    # back to processing
    state_transition :restart, :failed => :processing
  end
end