state_machine
https://github.com/pluginaweek/state_machine
Ruby
Adds support for creating state machines for attributes on any Ruby class
StateMachine::StateContext#transition
Creates a new transition that determines what to change the current state
to when an event fires from this state.
Since this transition is being defined within a state context, you do
*not* need to specify the <tt>:from</tt> option for the transition. For
example:
state_machine do
state :parked do
transition :to => :idling, :on => [:ignite, :shift_up] # Transitions to :idling
transition :from => [:idling, :parked], :on => :park, :unless => :seatbelt_on? # Transitions to :parked if seatbelt is off
end
end
See StateMachine::Machine#transition for a description of the possible
configurations for defining transitions.Edit
git clone [email protected]:pluginaweek/state_machine.git
cd state_machine
open lib/state_machine/state_context.rb
Contribute
# Make a new branchgit checkout -b -your-name--update-docs-StateMachine--StateContext-transition-for-pr
# Commit to gitgit add lib/state_machine/state_context.rbgit commit -m "better docs for StateMachine::StateContext#transition"
# Open pull requestgem install hub # on a mac you can `brew install hub`
hub fork
git push <your name> -your-name--update-docs-StateMachine--StateContext-transition-for-pr
hub pull-request
# Celebrate!