Read a route's version, anchor and requirements from its pattern#2783
Merged
Conversation
Danger ReportNo issues found. |
ec239e9 to
442088e
Compare
`version`, `anchor` and `requirements` are the attributes that shape the matcher — they are passed to `Grape::Router::Pattern` to build the mustermann pattern. They were also passed a second time to `Grape::Router::Route` and stored as ivars, purely to back the readers. Expose them on `Pattern` instead (`attr_reader`) and delegate the `BaseRoute` readers to `@pattern`, alongside the existing `path`/`origin` delegation. `to_routes` no longer passes them to `Route.new`. Metadata that does not shape matching — `namespace`, `prefix`, `settings` — stays as route keyword arguments. grape-swagger already passes these to `Pattern.new` and none of them to `Route.new`, so its routes' readers become correct rather than `nil`. Also collapse `extract_capture` to a guard plus a single merge. With the `format` keyword gone (#2782) it just adds an optional `version` constraint to `requirements`, so the intermediate accumulator was noise. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
442088e to
2e367f1
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.
Rebased onto master now that #2782 is merged.
version,anchorandrequirementsare the attributes that shape the matcher — they're passed toGrape::Router::Patternto build the mustermann pattern. But they were also passed toGrape::Router::Routeand stored as ivars, solely to back theroute.version/route.anchor/route.requirementsreaders. That's a redundant second copy.Change
Grape::Router::Patternnow stores and exposesanchor,version,requirements(attr_reader). Itsinitializesignature is unchanged.Grape::Router::BaseRoutedelegates those three readers to@pattern, alongside the existingdef_delegators :@pattern, :path, :origin. They're dropped from itsattr_reader,initializekeywords and ivars.Endpoint#to_routesno longer passes them toRoute.new.namespace,prefix,settings— stays asRoutekeyword arguments.The line is principled: the pattern owns the match parameters; the route owns the metadata.
Also collapses
extract_captureto a guard plus a single merge. With theformatkeyword gone (#2782) it just adds an optionalversionconstraint torequirements, so the intermediate accumulator hash was noise — this is the simplification that didn't make it into #2782 before it merged.Notes
anchor/version/requirementstoPattern.newand passes none of them toRoute.new, so its routes' readers become correct instead ofnil.GreedyRouteborrows another route's pattern, so itsversion/anchor/requirementsnow reflect that pattern rather thannil. Nothing reads them (the OPTIONS/405 suite is green), so it's invisible — noted for completeness.🤖 Generated with Claude Code