state_machine

https://github.com/pluginaweek/state_machine

Ruby

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

StateMachine::Machine.find_or_create

Attempts to find or create a state machine for the given class.  For
example,

  StateMachine::Machine.find_or_create(Vehicle)
  StateMachine::Machine.find_or_create(Vehicle, :initial => :parked)
  StateMachine::Machine.find_or_create(Vehicle, :status)
  StateMachine::Machine.find_or_create(Vehicle, :status, :initial => :parked)

If a machine of the given name already exists in one of the class's
superclasses, then a copy of that machine will be created and stored
in the new owner class (the original will remain unchanged).

Source | Google | Stack overflow

Edit

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

cd state_machine

open lib/state_machine/machine.rb

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-StateMachine--Machine-find_or_create-for-pr


# Commit to git

git add lib/state_machine/machine.rbgit commit -m "better docs for StateMachine::Machine.find_or_create"


# 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--Machine-find_or_create-for-pr

hub pull-request


# Celebrate!