geekq/workflow — pull request #109 by damncabbage (2014-07-22 05:39:23+00:00)
Title: Adds (optional) condition checks to Event transitions.

Conditions are procs or lambdas added to events, like so:

```ruby
state :off
event :turn_on, :transition_to => :on,
:if => proc { |device| device.battery_level > 0 }
event :turn_on, :transition_to => :low_battery,
:if => proc { |device| device.battery_level > 10 }
end
```

When calling a `device.can_?` check, or attempting a `device.!`, each event is checked in turn:

* With no :if check, proceed as usual.
* If an :if check is present, proceed if it evaluates to true, or drop to the next event.
* If you've run out of events to check (eg. battery_level == 0), then the transition isn't possible.