Skip to content

Conversation

@svoop
Copy link

@svoop svoop commented Jan 20, 2013

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 is 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!

@svoop
Copy link
Author

svoop commented Mar 8, 2013

@geekq The recent code reorganisation rendered my commit useless, I have therefore force pushed a version of my commit which can be merged. Unfortunately, your comments were zapped due to the force push. You mentioned plans to extract some code (such as state comparison) into it's own module. Please tell me if I can be of any help with this. In any case, this addition is not really related to state comparison. Even in cases where states are not compared, it may be useful to explicitly set an initial state in order to organize the workflow definition code ad lib.

@svoop svoop closed this Mar 9, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant