state_machine

https://github.com/pluginaweek/state_machine

Ruby

Adds support for creating state machines for attributes on any Ruby class

StateMachine::Transition#persist

Transitions the current value of the state to that specified by the
transition.  Once the state is persisted, it cannot be persisted again
until this transition is reset.

== Example

  class Vehicle
    state_machine do
      event :ignite do
        transition :parked => :idling
      end
    end
  end
  
  vehicle = Vehicle.new
  transition = StateMachine::Transition.new(vehicle, Vehicle.state_machine, :ignite, :parked, :idling)
  transition.persist
  
  vehicle.state   # => 'idling'

Source | Google | Stack overflow

Edit

git clone [email protected]:pluginaweek/state_machine.git

cd state_machine

open lib/state_machine/transition.rb

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-StateMachine--Transition-persist-for-pr


# Commit to git

git add lib/state_machine/transition.rbgit commit -m "better docs for StateMachine::Transition#persist"


# Open pull request

gem install hub # on a mac you can `brew install hub`

hub fork

git push <your name> -your-name--update-docs-StateMachine--Transition-persist-for-pr

hub pull-request


# Celebrate!