Skip to content

Commit 1982e5b

Browse files
aserafingeekq
authored andcommitted
allow event arguments to be taken into account when selecting the event
1 parent 9cb38d2 commit 1982e5b

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

lib/workflow.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def halted_because
9595
end
9696

9797
def process_event!(name, *args, **kwargs)
98-
event = current_state.events.first_applicable(name, self)
98+
event = current_state.events.first_applicable(name, self, args)
9999
raise NoTransitionAllowed.new(
100100
"There is no event #{name.to_sym} defined for the #{current_state} state") \
101101
if event.nil?

lib/workflow/event.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ def initialize(name, transitions_to, condition = nil, meta = {}, &action)
1515
end
1616
end
1717

18-
def condition_applicable?(object)
18+
def condition_applicable?(object, event_arguments)
1919
if condition
2020
if condition.is_a?(Symbol)
21-
object.send(condition)
21+
object.send(condition, *event_arguments)
2222
else
23-
condition.call(object)
23+
condition.call(object, *event_arguments)
2424
end
2525
else
2626
true

lib/workflow/event_collection.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ def include?(name_or_obj)
2626
end
2727
end
2828

29-
def first_applicable(name, object_context)
29+
def first_applicable(name, object_context, event_arguments)
3030
(self[name] || []).detect do |event|
31-
event.condition_applicable?(object_context) && event
31+
event.condition_applicable?(object_context, event_arguments) && event
3232
end
3333
end
3434

0 commit comments

Comments
 (0)