Add a state_transitions(requirements = {}) method #9

Open
wants to merge 1 commit into
from

Projects

None yet

2 participants

To access available transitions with 'from' state, 'to' state, both, or 'on' event.

# Assuming
  states :created, :started, :finished

  event :start,  :from => :created, :to => :started
  event :finish, :to => :finished, :after => :cleanup
# Example 1:
  self.state = :created
  state_transitions # Assumes :from => self.state

# Result:
  [{:event => :start, :from => :created, :to => :started}]
# Example 2:
  state_transitions(:from => :created, :to => :started)

# Result:
  [{:event => :start, :from => :created, :to => :started}]
# Example 3:
  state_transitions(:to => :finished)

# Result:
  [{:event => :finish, :from => [:created, :started], :to => :finished}]
# Example 4:
  state_transitions(:on => :finish)

# Result:
  [{:event => :finish, :from => [:created, :started], :to => :finished}]
# Example 5:
  state_transitions(:on => :finish, :from => :started)

# Result:
  [{:event => :finish, :from => [:started], :to => :finished}]

OK. I know the code in the pull isn't the smartest around but it works :p

This pull request passes (merged 8b423d0 into dee8f11).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment