Peter Marklund

Peter Marklund's Home

Mon June 16, 2008
Programming

Rails plugin: acts_as_state_machine_hacked

I've been using the acts_as_state_machine plugin in a couple of projects. I think the syntax and functionality of the plugin is quite nice. It allows you to easily define states and events (transitions between states) for your ActiveRecord model. However, I wanted to be able to see which states are available in the current state. Also I thought that invoking an event, such as user.activate!, when the user is in a state where the activate event is not available should not yield a silent failure, but rather throw an exception. Also, if the event fails to fire because of a guard condition then an exception should also be raised. I encapsulated those changes in the plugin acts_as_state_machine_hacked.

Comments

Chad Humphries said over 6 years ago:

Take a look at the newer version of acts as state machine at http://github.com/rubyist/aasm

--------------------------------------------------------------------------------