state_machine 0.8.1: The Ocho

by aaron

If you had asked me 6 months ago when the next release of state_machine was going to be, Pi Day 2010 would probably not have been my first guess. If it had been, I probably would have asked you to admit me into a hospital so I could be treated for delirium. Then again, what better way to celebrate such an important holiday?

Be a thinker, not a stinker. Or at least take a shower. Seriously.

Without further ado, I am excited to announce the release of state_machine 0.8.1. This is the most stable, feature-rich release yet. Given that I never officially announced the 0.8.0 release 6 months ago, below is a brief overview of everything that comes with the Ocho package:

  • ActiveRecord 2.0 and 3.0 support (Rails 3 users, rejoice!)
  • DataMapper 0.10 support
  • ruby-graphviz 0.9 support
  • Full compatibility with ORM dirty attribute tracking
  • Default state-driven behaviors
  • More control over whether after_transition callbacks get run after failed actions
  • Define multiple callbacks in a single before/after_transition call
  • ActiveRecord i18n support for state / event names
  • Query available state transitions with :from / :to / :on requirements
  • Earlier access to initial states during the initialization of an object
  • …and 20 bug fixes!

Here’s a very small bit of code demonstrating some of the visibily new features:

class Vehicle
  include DataMapper::Resource
 
  property :id, Serial
  property :state, :String
 
  state_machine do
    before_transition all => :parked, :do => [:set_alarm, :lock_doors]
    after_transition :do => :log_transition, :include_failures => true
 
    event :ignite { transition :parked => :first_gear }
    event :park { transition :first_gear => :parked }
 
    state :first_gear do
      def speed
        10
      end
    end
  end
 
  def speed
    0
  end
end
 
vehicle = Vehicle.new
vehicle.state_transitions
vehicle.state_transitions(:to => :parked)

See the full list of changes (and follow the project!) here. If you are on any other version, I strongly suggest (using <strong> tags, too) that you upgrade to 0.8.1. You’ll thank me later. Or you’ll yell at me for not releasing this earlier :)

I’d like to thank everyone at the academy who I paid off to vote for me.

As with every release, none of this would have been possible without the help of every person who filed a bug, sent me an e-mail, made a pull request, or tried to stalk me. The following Rubyists were particularly instrumental in putting this release together:

  • Jeremy Wells
  • Joe Lind
  • Jon Evans
  • Sandro Turriate
  • Tim Pope

I didn’t hear no bell. My hearing aid must be broken.

So where do we go from here? The road to 1.0 has been simple for me from the get-go. Over the past year or so, we’ve seen many Rubyists work together to standardize commonly-needed features through libraries like rack, i18n, activemodel, etc. That was exactly the goal for state_machine 1.0… to build a standardized implementation for state machines and become the recommended implementation for at least 1 of the 3 major Ruby ORMs. And that’s not something I can do without your help.

Either way, I’d love to hear feedback from the community. What do you think the 1.0 release should be (or should include)?

Hope you enjoyed some Pi. Delicious, delicious 3.14159……..

Comments

5 Responses to “state_machine 0.8.1: The Ocho”

  1. tarsolya on March 15th, 2010 4:51 am
  2. Netizer on March 15th, 2010 8:20 am

    no, it has not: http://github.com/rails/rails/commit/db49c706b62e7ea2ab93f05399dbfddf5087ee0c

    all the code has been extracted to the new gem by qooba. it is now called “transitions”.

  3. Winfield on March 15th, 2010 8:37 am

    Congrats, I know we’ll likely pick this up at PLM. Glad to see Joe’s fork brought back in.

  4. Dan Kubb on March 16th, 2010 2:43 pm

    Your state_machine gem is what I always recommend to people who use DataMapper, but I should probably make it official. I would like to actually deprecate the dm-is-state_machine gem, and replace it’s “guts” with your gem for the people who insist on using the gem for backwards compatibility reasons.

  5. Note to Self » Blog Archive » What I brought home from Scottish Ruby Conference on March 28th, 2010 3:21 pm

    [...] but says that it should probably be really easy to use state_machine instead. (NB: A new version of state machine was released two weeks ago with a lot of important [...]