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

Revisit versioner middlewares #2484

Merged
merged 3 commits into from
Jul 27, 2024

Conversation

ericproulx
Copy link
Contributor

@ericproulx ericproulx commented Jul 26, 2024

This PR is a refactor of all Grape::Middleware::Versioner

First, they all use the default_options like the other middlewares. Since default version_options is including another Hash, I had to replace merge by deep_merge in Grape::Middleware::Base.

Second, the using strategy is now dynamically solved like validators. It's all based on the name of the class.

Third, I've added a versioner_helpers that all Grape::Middleware::Versioner include. At least, all the options[...] are exposed through an helper function which reduces the [] calls.

Use `const_get` to find versioner
Grape::Middleware::Versioner::* uses `default_options` like other middlewares
Add versioner_helpers for Grape::Middleware::Versioner::*
Replace `merge` by `deep_merge` in Grape::Middleware::Base initialize
Add specs
Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

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

Comments below.

Beef up the description of the PR a bit to explain why this is better. Why is it? :)

lib/grape/middleware/versioner.rb Show resolved Hide resolved
lib/grape/middleware/versioner/accept_version_header.rb Outdated Show resolved Hide resolved
lib/grape/middleware/versioner/param.rb Outdated Show resolved Hide resolved
Use `camelize` instead of `classify`
@ericproulx ericproulx marked this pull request as ready for review July 27, 2024 10:09
Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

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

The entire spec/grape/util/accept_header_handler_spec.rb is gone. Where ele do we cover the accept version negotiation and x-cascade handling for that one in tests?

@ericproulx
Copy link
Contributor Author

The entire spec/grape/util/accept_header_handler_spec.rb is gone. Where ele do we cover the accept version negotiation and x-cascade handling for that one in tests?

There's already the accept_version_header_spec that covers all cases. Coverage is 100%

@ericproulx ericproulx requested a review from dblock July 27, 2024 18:33
@dblock dblock merged commit 2292486 into ruby-grape:master Jul 27, 2024
52 checks passed
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.

2 participants