state_machine

https://github.com/pluginaweek/state_machine

Ruby

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

StateMachine::InstanceMethods#fire_events!

Run one or more events in parallel.  If any event fails to run, then
a StateMachine::InvalidTransition exception will be raised.

See StateMachine::InstanceMethods#fire_events for more information.

== Example

  class Vehicle
    state_machine :initial => :parked do
      event :ignite do
        transition :parked => :idling
      end
      
      event :park do
        transition :idling => :parked
      end
    end
    
    state_machine :alarm_state, :namespace => 'alarm', :initial => :active do
      event :enable do
        transition all => :active
      end
      
      event :disable do
        transition all => :off
      end
    end
  end
  
  vehicle = Vehicle.new                         # => #<Vehicle:0xb7c02850 @state="parked", @alarm_state="active">
  vehicle.fire_events(:ignite, :disable_alarm)  # => true
  
  vehicle.fire_events!(:ignite, :disable_alarm) # => StateMachine::InvalidTranstion: Cannot run events in parallel: ignite, disable_alarm

Source | Google | Stack overflow

Edit

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

cd state_machine

open lib/state_machine/extensions.rb

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-StateMachine--InstanceMethods-fire_events--for-pr


# Commit to git

git add lib/state_machine/extensions.rbgit commit -m "better docs for StateMachine::InstanceMethods#fire_events!"


# 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--InstanceMethods-fire_events--for-pr

hub pull-request


# Celebrate!