Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

[Patch] Dynamically set initial state

#14

Warning: Feature Request. :-D

I'd like the ability to dynamically assign the initial state of an object instead of strictly assigning it to one specific state.

While I realize that traditional state machines have an initial state, flow, and often final state (or are alternatively ever-running) and that this request somewhat breaks that basic concept, I think it is a very useful feature.

Proposed implementation

Maybe there's already a simple way to do this, but I don't immediately see it. Looking at the aasm_initial_state method, it currently only accepts nothing or a state name. I propose that we have a third option of a Proc, which gets executed at the time of creation. That Proc could then return the name of the desired initial state.

Highly contrived example

Take for instance the case where you're working with objects which are dependents of a parent. At their time of creation, their initial state may differ depending on the parent's state or conditions.

So, maybe you've signed up for a free version of an account and have attempted to create additional users beyond your quota. Instead of restricting that addition, it instead allows you to add the user, but sets them as disabled, for example. Normally, those created users would be allowed in the system, but once you're past quota, those users are disabled on creation.

I'm more than willing to submit the patch for it, but before putting in the effort I wanted to be sure it was something that seemed acceptable upstream. :)

Reported by Nathaniel Bibler · February 26th, 2009 @ 11:16 AM

State: new
Milestone: none
Assigned to: Scott Barron Scott Barron

Activity

  1. Nathaniel Bibler
    Nathaniel Bibler
    • Tag changed from feature to feature, patch

    Here's a patch to add support for this request. Let me know what you think.

    February 26th, 2009 @ 12:39 PM

  2. Nathaniel Bibler
    Nathaniel Bibler

    A prettier version of that patch can be found here: http://github.com/nbibler/aasm/c...

    February 26th, 2009 @ 12:43 PM

  3. Nathaniel Bibler
    Nathaniel Bibler
    • Title changed from Dynamically set initial state to [Patch] Dynamically set initial state

    April 8th, 2009 @ 03:33 PM

  4. Travis Tilley

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.