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

Fix keyword parameters in ruby 3.2 #849

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/aasm/core/invokers/literal_invoker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,21 @@ def exec_subject
raise(*record_error) unless record.respond_to?(subject, true)
return record.__send__(subject) if subject_arity.zero?
return record.__send__(subject, *args) if subject_arity < 0
req_args = args[0..(subject_arity - 1)]
return record.__send__(subject, **req_args[0]) if req_args[0].is_a?(Hash)
record.__send__(subject, *req_args)
handle_args
end
# rubocop:enable Metrics/AbcSize

def handle_args
req_args = args[0..(subject_arity - 1)]
if req_args[-1].is_a?(Hash)
positional_args = req_args[0..-2]
kw = req_args[-1]
record.__send__(subject, *positional_args, **kw)
else
record.__send__(subject, *req_args)
end
end

def record_error
[
NoMethodError,
Expand Down
8 changes: 8 additions & 0 deletions spec/models/event_with_keyword_arguments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ class EventWithKeywordArguments
before :_before_close
transitions from: :open, to: :closed
end

event :another_close do
before :_before_another_close
transitions from: :open, to: :closed
end
end

def _before_close(key:)
end

def before_another_close(key:)
end
end
4 changes: 4 additions & 0 deletions spec/unit/event_with_keyword_arguments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
it 'should be executed correctly that method registered by "before hooks" for events with keyword arguments.' do
expect(example.close(key: 1)).to be_truthy
end

it 'should be executed correctly that method registered by "before hooks" for events with positional and keyword arguments.' do
expect(example.close(1, key: 1)).to be_truthy
end
end
end