Skip to content

Nest Grape::Path inside Grape::Router::Pattern#2792

Merged
ericproulx merged 2 commits into
masterfrom
refactor/nest-path-in-pattern
Jul 12, 2026
Merged

Nest Grape::Path inside Grape::Router::Pattern#2792
ericproulx merged 2 commits into
masterfrom
refactor/nest-path-in-pattern

Conversation

@ericproulx

Copy link
Copy Markdown
Contributor

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) and only its .origin/.suffix were ever read, yet it sat at the top level of the Grape namespace as if it were public API.

Change

  • Move it to Grape::Router::Pattern::Path — where it belongs, as a router-internal collaborator of Pattern.
  • Add a Pattern.build(path:, namespace:, settings:, anchor:, params:, version:, requirements:) factory that constructs the Path internally and derives origin/suffix from it. The endpoint now makes a single call instead of building a Path and threading its outputs into Pattern.new:
# before
prepared_path = Path.new(path, namespace, path_settings)
pattern = Grape::Router::Pattern.new(origin: prepared_path.origin, suffix: prepared_path.suffix, anchor:, params: route_options[:params], version:, requirements:)

# after
pattern = Grape::Router::Pattern.build(path:, namespace:, settings: path_settings, anchor:, params: route_options[:params], version:, requirements:)

Pattern.new is 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). Only Path, and the thin build factory, are settings-aware. Path keeps its own class and spec.

Grape::Path is retained as a deprecated ActiveSupport::Deprecation::DeprecatedConstantProxy pointing at the new constant, so external references keep working with a warning.

Tests

  • spec/grape/path_spec.rb moved to spec/grape/router/pattern/path_spec.rb (unchanged assertions, new constant), plus a small spec/grape/path_spec.rb that asserts the old constant is deprecated.
  • Added a Pattern.build example. Full suite: 2353 examples, 0 failures. RuboCop clean. Verified require 'grape' (which eager-loads) works with the proxy under deprecator.behavior = :raise.

🤖 Generated with Claude Code

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>
@ericproulx ericproulx force-pushed the refactor/nest-path-in-pattern branch from db45362 to eaaee65 Compare July 11, 2026 07:16
@github-actions

github-actions Bot commented Jul 11, 2026

Copy link
Copy Markdown

Danger Report

No issues found.

View run

@ericproulx ericproulx merged commit d713797 into master Jul 12, 2026
69 checks passed
@ericproulx ericproulx deleted the refactor/nest-path-in-pattern branch July 12, 2026 16:30
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