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 using methods with keyword arguments in search DSL with Ruby > 3 #1026

Merged

Conversation

andreslemik
Copy link
Contributor

@andreslemik andreslemik commented Mar 15, 2023

Example:

# ruby 3.2
def kwargs_method(first:, second:)
  [first, second]
end

Sunspot.search(Post) do
  with :some_field, kwargs_method(first: 1, second: 2) # with :some_field, [1,2]
end

@andreslemik andreslemik changed the title Allow using methods with keyword arguments in search DSL Allow using methods with keyword arguments in search DSL with Ruby > 3 Mar 15, 2023
def method_missing(method, *args, &block)
__proxy_method__(method, *args, &block)
end
if RUBY_VERSION >= '3.0'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there something that isn't backwards compatible with Ruby 2.x in here? Could we just use the new kwargs code for all versions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, this code should work with all 2.x versions. I checked it with version 2.7 and it works.

@njakobsen njakobsen merged commit 414a594 into sunspot:master Mar 23, 2023
@andreslemik andreslemik deleted the ruby3-kwordargs-methods-delegation branch March 23, 2023 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants