Skip to content

Internalize namespace and mount-path registrations behind Grape::Util::InheritableSetting accessors#2803

Open
ericproulx wants to merge 1 commit into
masterfrom
inheritable-setting-routing-scopes
Open

Internalize namespace and mount-path registrations behind Grape::Util::InheritableSetting accessors#2803
ericproulx wants to merge 1 commit into
masterfrom
inheritable-setting-routing-scopes

Conversation

@ericproulx

Copy link
Copy Markdown
Contributor

Continues the InheritableSetting cleanup from #2795#2802: the Grape::Namespace objects registered by the namespace DSL (and its group / resource / resources / segment aliases) and the mount path recorded by mount are now written and read through intention-revealing accessors on Grape::Util::InheritableSetting, so no caller indexes into namespace_stackable for these keys anymore.

New accessors on InheritableSetting

Accessor Replaces
namespaces / add_namespace(namespace) namespace_stackable[:namespace]
namespace_path Grape::Namespace.joined_space_path(namespace_stackable[:namespace])
namespace_requirements namespace_stackable[:namespace].filter_map(&:requirements)
mount_path / add_mount_path(path) namespace_stackable[:mount_path] / .first

Notes:

  • The two derived readers absorb the read conventions previously spelled out at the call sites: namespace_path performs the joined-and-normalized prefix lookup used by both Endpoint#namespace and the namespace DSL getter, and namespace_requirements performs the requirements filter_map used by Endpoint#prepare_routes_requirements (still returning a fresh Array, which that call site appends to).
  • mount_path absorbs the outermost-wins .first previously done in Endpoint#build_stack when configuring the versioner middleware, and documents it: with nested mounts the stack carries one entry per mount level, outermost first. The write side (add_mount_path) is recorded on the mounted API's top-level settings by DSL::Routing#mount, as before.
  • Naming: the raw-stack reader is namespaces (plural) because InheritableSetting#namespace already exists as the reader for the InheritableValues namespace store; the doc comments call out the distinction.
  • Also fixes the @param doc on Grape::Namespace.joined_space_path, which claimed the argument is a list of InheritableSettings — it has always been a list of Grape::Namespace objects.
  • Storage under the raw keys is unchanged, so to_hash output, route pattern settings (settings[:mount_path] in Router::Pattern::Path, which reads the stacked Array via to_hash) and any external readers see the same values; the raw keys should now be considered internal.

🤖 Generated with Claude Code

…::InheritableSetting accessors

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Danger Report

No issues found.

View run

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.

1 participant