geekq/workflow — pull request #64 by svoop (2013-01-20 11:58:22+00:00)
Title: Allow a workflow to be assigned an initial state different from the first state declared.

My current use case is a model for outgoing payments with the following workflow:

workflow do
initial_state :pending

state :incomplete do
event :check, transitions_to: :pending
end

state :pending do
event :hold, transitions_to: :held
event :confirm, transitions_to: :sent
end

state :held do
event :release, transitions_to: :pending
end

state :sent
end

The payout falls into `:incomplete` state if the prerequisites (which are more than validations alone) are not met. However, a new payout should be born with `:pending` state for reasons beyond my control.

I could of course declare the `:incomplete` state last, but since one of the previous extensions of the workflow gem `include Comparable` and thus allow states to be compared by declaration order e.g. with `>` or `<`, the right place of this state ist first.

The `initial_state` is completely optional. Unless present, the first state declared will automatically become the initial state and therefore this commit is fully backwards compatible and shouldn't break any existing code.

Thanks for considering this addition!