Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/workflow/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ def condition_applicable?(object, event_arguments)
object.send(condition, *event_arguments)
end
else
# since blocks can ignore extra arguments without raising an error in Ruby,
# no `if` is needed - compare with `arity` switch in above methods handling
condition.call(object, *event_arguments)
# Blocks and non-lambda Procs can ignore extra arguments without raising an error in Ruby,
# but lambdas cannot, so we still have to check arity
if condition.arity == 1 # no additional parameters accepted
condition.call(object)
else
condition.call(object, *event_arguments)
end
end
else
true
Expand Down
3 changes: 2 additions & 1 deletion test/conditionals_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def check_low_battery?() # supports no arguments, lets test below, what happens
event :turn_on, :transitions_to => :low_battery # otherwise
end
state :on do
event :check, :transitions_to => :low_battery, :if => proc { |obj| return false }
# Use a lambda proc, which enforces correct arity
event :check, :transitions_to => :low_battery, :if => -> (obj) { return false }
event :check, :transitions_to => :on # stay in on state otherwise
end
state :low_battery
Expand Down