Make requirements and anchor first-class endpoint inputs#2786
Open
ericproulx wants to merge 1 commit into
Open
Make requirements and anchor first-class endpoint inputs#2786ericproulx wants to merge 1 commit into
ericproulx wants to merge 1 commit into
Conversation
549990d to
d69ead8
Compare
Danger ReportNo issues found. |
21695b8 to
2e21378
Compare
d69ead8 to
269e2b3
Compare
Contributor
Author
|
@dblock this is a stack PR. |
`route`'s documented options `requirements:` and `anchor:` are now explicit
keyword arguments rather than opaque keys in the `route_options` bag, with
`**route_options` still catching any custom options. They travel as their
own endpoint inputs (`Grape::Endpoint::Options` gains `:requirements` and
`:anchor` members; `Grape::Endpoint.new` gains matching keywords) and
`to_routes` reads them via `config.requirements` / `config.anchor` instead
of `route_options[...]`. The verb methods forward `**options` unchanged, so
`get(':id', requirements: {...}, anchor: false)` still works.
Like `params`, they no longer appear in `route.options`; the effective value
comes from the `route.requirements` / `route.anchor` readers. Mounts pass
`anchor: false` as a keyword too.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
269e2b3 to
cfaebfd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #2785.
Follows the same direction as #2785 (first-class
params):route's two documented, Grape-consumed options —requirements:andanchor:— become explicit keyword arguments instead of opaque keys read out of theroute_optionsbag.**route_optionsstill catches any custom options (e.g. grape-swagger metadata passed inline).What changed
route(methods, paths, requirements: nil, anchor: true, **route_options, &)— the two documented options are now named parameters; everything else flows through**route_optionsas before.Grape::Endpoint::Optionsgains:requirementsand:anchormembers, andGrape::Endpoint.newmatchingrequirements:/anchor:keywords.to_routesreadsconfig.requirements/config.anchorinstead ofroute_options[:requirements]/route_options.fetch(:anchor, true).mountpassesanchor: falseas a keyword rather thanroute_options: { anchor: false }.get/post/…) are left as pure**optionsforwarders —routeis the single source of truth for these options and their defaults.Behavior
get(':id', requirements: { id: /[0-9]+/ })still enforces the constraint;get('/(*:path)', anchor: false)and mounted apps still match as catch-alls.paramsin Make route params a first-class endpoint input and split Route#params #2785,requirements/anchorno longer appear inroute.options(route.options[:anchor]→nil); the effective value comes from theroute.requirements/route.anchorreaders. This refines the note added in Promote route metadata to Route keyword arguments #2779 (they previously still appeared in the bag). Nothing in Grape or grape-swagger read them that way.UPGRADING updated (the #2779 caveat corrected + a parallel note added). Full suite green (2353 examples, 0 failures); RuboCop clean.
🤖 Generated with Claude Code