state_machine

https://github.com/pluginaweek/state_machine

Ruby

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

StateMachine::Transition#perform

Runs the actual transition and any before/after callbacks associated
with the transition.  The action associated with the transition/machine
can be skipped by passing in +false+.

== Examples

  class Vehicle
    state_machine :action => :save do
      ...
    end
  end
  
  vehicle = Vehicle.new
  transition = StateMachine::Transition.new(vehicle, machine, :ignite, :parked, :idling)
  transition.perform                  # => Runs the +save+ action after setting the state attribute
  transition.perform(false)           # => Only sets the state attribute
  transition.perform(Time.now)        # => Passes in additional arguments and runs the +save+ action
  transition.perform(Time.now, false) # => Passes in additional arguments and only sets the state attribute

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-perform-for-pr


# Commit to git

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


# 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-perform-for-pr

hub pull-request


# Celebrate!