GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Merge branch 'state_machine'

Some big changes:
  * Added some redundant requires so active_support/inflecto can be loaded

      without the rest of ActiveSupport.
  * Disabled callbacks and validations until they are added and tested.
  * Converted specs back to tests, using ActiveSupport::TestCase and the 
  new
    #test helper.
  * As an experiment, I imported Scott Barron's awesome AASM gem into
    ActiveModel.  I added multiple state machine support and vastly 
    improved
    the API (no more aasm_* prefixes).  All the old tests pass.  If this 
    bothers
    people, I have no problems removing this and contributing the changes 
    back to
    AASM.  I just feel like AMo is a better spot for all these 'modelish' 
    features.
technoweenie (author)
Sun Jun 29 12:13:58 -0700 2008
commit  01db5ded54b0e3a2ea80d28e4841d40fcec23cdf
tree    9d30b4c51da7e8f0fb0fc77126450f63fd08e8fa
parent  4cf93935b2478201863c01569e894c9dcf7e9074 parent  c9e366e997c6f3a383cfaa6351fa847e92de7fe4

Comments

  • I am very excited by this, Rick.

    I have been using AASM — slightly modified by Jeffrey Hardy — on every project I’ve worked on since it was released.

    I’m shocked that a bigger deal hasn’t been made about this being added.

  • I sent a notice over to Gregg at RailsEnvy (http://www.railsenvy.com) on June 29 and it was mentioned in the podcast, episode #36, 7/2/08.

    I think including AASM functionality in core a great idea. I’m sure a lot of people will think that Rails is just gaining more bloat, but state machines are extremely valuable to software projects. I’ve used AASM in several, if not all of my projects over the past few years. I’m also curious as to why more people haven’t picked up on it, but as always, the community is very fickle. Glad to see it added.

  • This is added to Active Model, not directly to Active Record, which may explain why not many have covered it. From my understanding we won’t be seeing it in Active Model / Active Resource until a while longer. Someone please correct me if I’m wrong.

  • correction: From my understanding we won’t be seeing it in Active Record / Active Resource until a while longer.

  • Also, I don’t plan to include this in ActiveRecord by default. It’ll be available if you want to require ‘active_model/state_machine’ and include the model (hello plugin!).

    We’ll be doing some stuff to integrate validations/callbacks into AMo::StateMachine as well, rather than the custom callback/guard system that it uses.

  • Nice. I know in at least one of my AASM projects I had to give it major overhaul to support transitions not only with guards, but also restricted to user roles. Something similar to before_filters might be nice so that we could chain guard calls and whatnot.

  • Perhaps a blog post to explain all the ActiveModel/Record/Resource gameplan?

  • Second chrislloyd

  • I’m glad I kick-started some discussion around this!

    Rick, I’d love it if you took some time to make a quick syntax proposal. It seems that the original AASM and what you intend to end up with are going to be very different beasts.

    I’m all for changing my approach when it’s better, but I’d value the opportunity to participate in some brainstorming around the invocation and syntax for what you have in mind. I’m already using a slightly modified AASM and as with all things, there’s usually a few ways to do the same things… often it just boils down to aesthetics.

  • I must be the only person here who believes this, but including state machine support I feel is bloat and is better off being a plugin like acts_as_list, acts_as_tree, and all the others. Is that not the reason those were pulled out of Rails to begin with? Or was it that it didn’t meet the 80/20 mark? Perhaps it’s my misunderstanding of the purpose of ActiveModel. I use state machines in most projects myself (see http://github.com/pluginaweek/state_machine), so I certainly agree that state machines are extremely valuable to software projects. However, ActiveModel feels like the wrong place for something like this to exist.

  • I am very excited about this commit and having integrated validations/callbacks sounds intriguing.

  • Have you considered stateful instead of aasm (http://github.com/jbarnette/stateful/tree/master)? Or, at least, will this make projects like stateful more difficult to use?

    It apparently allows you to have state on every ruby class you want and the syntax seems a bit nicer than aasm.

  • Rick and I have talked a bit about this on #rails-contrib: While I (obviously) prefer Stateful’s syntax, AASM has a fair amount of additional features (multiple state machines, guards), and it’s mature and battle-tested. I think this is probably the right direction :)

  • I actually spent a lot of time today playing with obrie’s state_machine, and I’m reasonably confident that it’s even better than AASM, with a very similar syntax. It supports multiple states on a single model, as well as :initial => Proc.new which is something I’ve always wanted with AASM.

    Now I’m busy converting my active project, and I think the biggest difference is that you don’t have to define a fixed list of states.