svenfuchs/simple_states — pull request #9 by Gurpartap (2012-05-28 02:48:32+00:00)
Title: Add a state_transitions(requirements = {}) method

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

```
# Assuming
states :created, :started, :finished

event :start, :from => :created, :to => :started, :if => :startable?
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 cleanest around but it works :p