geekq / workflow

Ruby finite-state-machine-inspired API for modeling workflow
MIT License
1.75k stars 207 forks source link

Add support for specifying event `if` conditions with a method name symbol #113

Closed virtualstaticvoid closed 9 years ago

virtualstaticvoid commented 10 years ago

Add the ability to define if conditions for events using an instance method name symbol, in addition to the already supported proc or lambda way.

state :off
  event :turn_on, :transition_to => :on,
                  :if => :sufficient_battery_level?

  event :turn_on, :transition_to => :low_battery,
                  :if => proc { |device| device.battery_level > 0 }
end

# corresponding instance method
def sufficient_battery_level?
  battery_level > 10
end

Here, the :sufficient_battery_level? method is invoked when evaluating the condition.

virtualstaticvoid commented 10 years ago

Hi @geekq

Sorry to bug you. Have you had a chance to review this pull request, and if so could it be merged? It would really be great if conditions could be specified using this technique which is a familiar pattern in Rails.

Thanks

virtualstaticvoid commented 9 years ago

Awesome, thanks for merging!

hmaack commented 9 years ago

:+1: