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. :)