Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mnutt/acts_as_state_machine
acts_as_state_machine
https://github.com/mnutt/acts_as_state_machine
Last synced: about 2 months ago
JSON representation
acts_as_state_machine
- Host: GitHub
- URL: https://github.com/mnutt/acts_as_state_machine
- Owner: mnutt
- License: mit
- Created: 2009-03-31T20:32:10.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2009-03-31T20:32:29.000Z (over 15 years ago)
- Last Synced: 2024-04-08T15:45:50.259Z (9 months ago)
- Language: Ruby
- Homepage:
- Size: 97.7 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README
- Changelog: CHANGELOG
- License: MIT-LICENSE
Awesome Lists containing this project
README
= 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 => :openedstate :opened
state :closed, :enter => Proc.new {|o| Mailer.send_notice(o)}
state :returnedevent :close do
transitions :to => :closed, :from => :opened
endevent :return do
transitions :to => :returned, :from => :closed
end
endo = Order.create
o.close! # notice is sent by mailer
o.return!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 closedand so on
For more information on named scopes see
http://railscasts.com/episodes/108