public
Description: git mirror of acts_as_state_machine
Homepage: http://elitists.textdriven.com/svn/plugins/acts_as_state_machine/
Clone URL: git://github.com/freels/acts_as_state_machine.git
100644 34 lines (22 sloc) 0.692 kb
1
2
3
4
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
= Acts As State Machine
 
This act gives an Active Record model the ability to act as a finite state
machine (FSM).
 
Acquire via subversion at:
 
http://elitists.textdriven.com/svn/plugins/acts_as_state_machine/trunk
 
If prompted, use the user/pass anonymous/anonymous.
 
== Example
 
 class Order < ActiveRecord::Base
   acts_as_state_machine :initial => :opened
 
   state :opened
   state :closed, :enter => Proc.new {|o| Mailer.send_notice(o)}
   state :returned
 
   event :close do
     transitions :to => :closed, :from => :opened
   end
 
   event :return do
     transitions :to => :returned, :from => :closed
   end
 end
 
 o = Order.create
 o.close! # notice is sent by mailer
 o.return!