workflow
workflow copied to clipboard
allow event arguments to be taken into account when selecting the event
This allows access to event arguments when we're evaluating which event to run in the scope of
state :off
event :turn_on, :transition_to => :on, :if => :sufficient_battery_level?
event :turn_on, :transition_to => :low_battery, :if => proc { |device, _power_adapter| device.battery_level > 0 }
end
# corresponding instance method
def sufficient_battery_level?(power_adapter)
power_adapter || battery_level > 10
end
@geekq I imagine this potentially is a breaking change but I run into a situation when event arguments had to be taken into account for conditional event - let me know what you think 👍 🙇
Thanks for your contribution! Backward compatibility is very important (people have used this library for many years, and some do not upgrade to the newest Ruby or Rails versions). The compatibility should be covered (checked) by the test suite though. Good thing would be to switch from travis-CI (ceased) to GitHub actions, before integrating any new contributions. Maybe something inspired by https://github.com/geekq/workflow-activerecord/blob/develop/.github/workflows/test.yml so any regression can be prevented.
For the new behavior we'll need test cases as well.
Blocked by gh-229
Please rebase your PR, so we can see the results of the tests for different Ruby versions