Find file
Fetching contributors…
Cannot retrieve contributors at this time
42 lines (28 sloc) 1017 Bytes
= 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:
If prompted, use the user/pass anonymous/anonymous.
== Example
class Order < ActiveRecord::Base
acts_as_state_machine :initial => :opened
state :opened
state :closed, :enter => {|o| Mailer.send_notice(o)}
state :returned
event :close do
transitions :to => :closed, :from => :opened
event :return do
transitions :to => :returned, :from => :closed
o = Order.create
o.close! # notice is sent by mailer
This version of State Machine will additionally create named scopes for your states - referring to the above example
Order.opened will return all orders with a state of opened
Order.closed will return all models with a state of closed
and so on
For more information on named scopes see