Nest Grape::Path inside Grape::Router::Pattern#2792
Merged
Conversation
Grape::Path only ever existed to compute the origin/suffix strings that Grape::Router::Pattern compiles into a matcher — it had a single caller (Endpoint#to_routes) yet sat at the top level of the Grape namespace as if it were public. Move it to Grape::Router::Pattern::Path and add a Pattern.build factory that takes the raw path, namespace and inheritable settings and constructs the Path internally, so the endpoint makes one call instead of building a Path and threading its origin/suffix into Pattern.new. Pattern.new stays value-based (origin:/suffix:/...), so the matcher never learns about the settings-hash shape; only Path (and the thin factory) is settings-aware. Grape::Path is kept as a deprecated constant proxy to the new location. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
db45362 to
eaaee65
Compare
Danger ReportNo issues found. |
dblock
approved these changes
Jul 12, 2026
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.
Grape::Pathonly ever existed to compute theorigin/suffixstrings thatGrape::Router::Patterncompiles into a matcher. It had a single caller (Endpoint#to_routes) and only its.origin/.suffixwere ever read, yet it sat at the top level of theGrapenamespace as if it were public API.Change
Grape::Router::Pattern::Path— where it belongs, as a router-internal collaborator ofPattern.Pattern.build(path:, namespace:, settings:, anchor:, params:, version:, requirements:)factory that constructs thePathinternally and derivesorigin/suffixfrom it. The endpoint now makes a single call instead of building aPathand threading its outputs intoPattern.new:Pattern.newis intentionally left value-based (origin:/suffix:/…) — the matcher never learns about the settings-hash shape (version_options.using,content_types,format,mount_path,root_prefix). OnlyPath, and the thinbuildfactory, are settings-aware.Pathkeeps its own class and spec.Grape::Pathis retained as a deprecatedActiveSupport::Deprecation::DeprecatedConstantProxypointing at the new constant, so external references keep working with a warning.Tests
spec/grape/path_spec.rbmoved tospec/grape/router/pattern/path_spec.rb(unchanged assertions, new constant), plus a smallspec/grape/path_spec.rbthat asserts the old constant is deprecated.Pattern.buildexample. Full suite: 2353 examples, 0 failures. RuboCop clean. Verifiedrequire 'grape'(which eager-loads) works with the proxy underdeprecator.behavior = :raise.🤖 Generated with Claude Code