workflow icon indicating copy to clipboard operation
workflow copied to clipboard

allow event arguments to be taken into account when selecting the event

Open aserafin opened this issue 3 years ago • 3 comments

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 👍 🙇

aserafin avatar May 20 '22 11:05 aserafin

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.

geekq avatar May 23 '22 14:05 geekq

Blocked by gh-229

geekq avatar May 25 '22 18:05 geekq

Please rebase your PR, so we can see the results of the tests for different Ruby versions

geekq avatar May 26 '22 17:05 geekq