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

Support Ruby 3 keyword arguments #97

Merged
merged 5 commits into from
Dec 30, 2019

Conversation

mame
Copy link
Contributor

@mame mame commented Dec 13, 2019

mame added 4 commits December 13, 2019 16:12
Since Ruby 2.7, `[**empty_hash]` returns `[]` instead of `[{}]`.

FYI: `[{ **f1, **f2 }]` also works.
The code depends upon `patterns_from(pattern, **empty_hash)` that passes
an empty hash as the second argument.  Since 2.7, it passes only one
positional argument.

I think that the intention here is to skip pattern generation when
`options` are empty and when `pattern` is a Pattern object.
This changeset makes it more explicit.
The code expects `foo("a" => 1, :b => 2)` to pass one positional
argument `{"a"=>1}` and one keyword argument `{:b=>2}`, but
unfortunately, this behavior of Hsah separation was a bug of Ruby 2.6 or
prior.  Since Ruby 2.7, non-Symbol key is allowed as keyword arguments,
so both are passed as keyword arguments.

This changeset adds braces to some method calls to pass a Hash object.
@dentarg
Copy link
Member

dentarg commented Dec 13, 2019

@mame don't you need to add the ruby2_keywords gem to the gemspec too?

@mame
Copy link
Contributor Author

mame commented Dec 14, 2019

@dentarg Yes, I will do later. Thank you dor pointing that out.

@jeremyevans
Copy link

The keyword argument separation issues in mustermann that this pull request fixes are currently blocking the separation of positional and keyword arguments in Ruby 3 development (ruby/ruby#2794). If this pull request could be given priority, I would appreciate it. @mame, could you add a commit that updates the gemspec? @dentarg, is there anything else that needs to be done before this is merged?

@mame
Copy link
Contributor Author

mame commented Dec 29, 2019

Sorry, I forgot it! Will do soon

@dentarg
Copy link
Member

dentarg commented Dec 29, 2019

@jeremyevans Not sure I can answer that, I just happened to see this one thing, other than that, I'm not really familiar with mustermann. It's @namusyaka that's been merging the most recent PRs. Perhaps @jkowens (or @zzak) can also help here?

@jkowens
Copy link
Member

jkowens commented Dec 30, 2019

This looks good to me. I'd be fine merging it in, but I don't think I have access to do any releases. So I guess that's not super helpful 😦

Hopefully @namusyaka will have a chance to chime in.

@namusyaka namusyaka self-assigned this Dec 30, 2019
@namusyaka namusyaka self-requested a review December 30, 2019 03:53
@namusyaka
Copy link
Member

Will do soon. Sorry for the late action.

Copy link
Member

@namusyaka namusyaka left a comment

Choose a reason for hiding this comment

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

LGTM with a nit, but I don't think it's not a blocker for us.
After getting merged, we can follow up on the nit if necessary.

Thanks for your work, @mame!

its(:to_h) { should be == { Mustermann.new("/foo") => Mustermann::Expander.new("/bar") } }
example { mapper['/foo'].should be == '/bar' }
example { mapper['/fox'].should be == '/fox' }
end

context 'allows specifying type' do
subject(:mapper) { Mustermann::Mapper.new(additional_values: :raise, type: :rails, "/foo" => "/bar") }
subject(:mapper) { Mustermann::Mapper.new({ "/foo" => "/bar" }, additional_values: :raise, type: :rails) }
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to update an example here?

@namusyaka namusyaka merged commit 107132b into sinatra:master Dec 30, 2019
namusyaka added a commit that referenced this pull request Dec 30, 2019
@namusyaka
Copy link
Member

@mame @jeremyevans Now the PR has been merged, and a new version including the changes has been released: https://rubygems.org/gems/mustermann/versions/1.1.0

ghost pushed a commit to rubygems/bundler that referenced this pull request Dec 31, 2019
7526: Fix CI failure with mustermann 1.1.0 r=deivid-rodriguez a=kou

### What was the end-user problem that led to this PR?

This PR doesn't fix any end-user problem.

This PR fixes a developer problem. Our CI is failed with mustermann 1.1.0.

### What was your diagnosis of the problem?

This is caused because mustermann 1.1.0 starts depending on ruby2_keyword gem but our test script doesn't add a load path for ruby2_keyword gem yet.

See also:

  * The PR that adds ruby2_keyword gem dependency to mustermann: sinatra/mustermann#97
  * Error message on CI: #7523 (comment)

### What is your fix for the problem, implemented in this PR?

My fix adds a load path for ruby2_keywrod gem installed in `tmp/1/gems/`.

### Why did you choose this fix out of the possible options?

I don't have another option.


Co-authored-by: Sutou Kouhei <[email protected]>
deivid-rodriguez pushed a commit to rubygems/bundler that referenced this pull request Jan 1, 2020
7526: Fix CI failure with mustermann 1.1.0 r=deivid-rodriguez a=kou

### What was the end-user problem that led to this PR?

This PR doesn't fix any end-user problem.

This PR fixes a developer problem. Our CI is failed with mustermann 1.1.0.

### What was your diagnosis of the problem?

This is caused because mustermann 1.1.0 starts depending on ruby2_keyword gem but our test script doesn't add a load path for ruby2_keyword gem yet.

See also:

  * The PR that adds ruby2_keyword gem dependency to mustermann: sinatra/mustermann#97
  * Error message on CI: #7523 (comment)

### What is your fix for the problem, implemented in this PR?

My fix adds a load path for ruby2_keywrod gem installed in `tmp/1/gems/`.

### Why did you choose this fix out of the possible options?

I don't have another option.

Co-authored-by: Sutou Kouhei <[email protected]>
(cherry picked from commit 984bef1)
ghost pushed a commit to rubygems/rubygems that referenced this pull request Mar 11, 2020
7526: Fix CI failure with mustermann 1.1.0 r=deivid-rodriguez a=kou

### What was the end-user problem that led to this PR?

This PR doesn't fix any end-user problem.

This PR fixes a developer problem. Our CI is failed with mustermann 1.1.0.

### What was your diagnosis of the problem?

This is caused because mustermann 1.1.0 starts depending on ruby2_keyword gem but our test script doesn't add a load path for ruby2_keyword gem yet.

See also:

  * The PR that adds ruby2_keyword gem dependency to mustermann: sinatra/mustermann#97
  * Error message on CI: rubygems/bundler#7523 (comment)

### What is your fix for the problem, implemented in this PR?

My fix adds a load path for ruby2_keywrod gem installed in `tmp/1/gems/`.

### Why did you choose this fix out of the possible options?

I don't have another option.


Co-authored-by: Sutou Kouhei <[email protected]>
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.

5 participants