Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion lib/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def halted_because
end

def process_event!(name, *args)
event = current_state.events.first_applicable(name, self)
event = current_state.events.first_applicable(name, self, args)
raise NoTransitionAllowed.new(
"There is no event #{name.to_sym} defined for the #{current_state} state") \
if event.nil?
Expand Down
6 changes: 3 additions & 3 deletions lib/workflow/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ def initialize(name, transitions_to, condition = nil, meta = {}, &action)
end
end

def condition_applicable?(object)
def condition_applicable?(object, event_arguments)
if condition
if condition.is_a?(Symbol)
object.send(condition)
object.send(condition, *event_arguments)
else
condition.call(object)
condition.call(object, *event_arguments)
end
else
true
Expand Down
4 changes: 2 additions & 2 deletions lib/workflow/event_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def include?(name_or_obj)
end
end

def first_applicable(name, object_context)
def first_applicable(name, object_context, event_arguments)
(self[name] || []).detect do |event|
event.condition_applicable?(object_context) && event
event.condition_applicable?(object_context, event_arguments) && event
end
end

Expand Down