Skip to content

Tighten dynamic define_method in callbacks/routing DSL#2708

Merged
dblock merged 1 commit into
masterfrom
refactor/define-method-cleanup
May 14, 2026
Merged

Tighten dynamic define_method in callbacks/routing DSL#2708
dblock merged 1 commit into
masterfrom
refactor/define-method-cleanup

Conversation

@ericproulx
Copy link
Copy Markdown
Contributor

Summary

Two small refinements to dynamic define_method blocks in the DSL:

  • lib/grape/dsl/callbacks.rb — the existing block called callback_method.pluralize.to_sym inside each generated method, so every invocation of before/after/etc. re-ran pluralize and allocated a fresh symbol. Replaced with a literal {method_name => plural_key} hash so the namespace_stackable key is a constant resolved at load time.
  • lib/grape/dsl/routing.rb — the per-verb method (get, post, …) was defined as |*args, **options, &block| and then computed paths = args.first || ['/']. Replaced with |path = '/', **options, &block| so the signature reflects the contract (a single path or default '/'), removing the splat allocation and array-of-arrays default. Updated to pass path (singular) to route, which already accepts both forms.

No behaviour change for documented call sites; both methods still accept the same arguments as before.

Test plan

  • bundle exec rspec
  • CI green

🤖 Generated with Claude Code

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 12, 2026

Danger Report

No issues found.

View run

@ericproulx ericproulx force-pushed the refactor/define-method-cleanup branch from f7d3df4 to 52959ef Compare May 12, 2026 06:55
@ericproulx ericproulx requested a review from dblock May 12, 2026 06:57
@ericproulx ericproulx force-pushed the refactor/define-method-cleanup branch 2 times, most recently from 26039f3 to 244cbb9 Compare May 12, 2026 07:00
- callbacks: replace runtime `pluralize.to_sym` with a precomputed
  `method_name -> plural_key` mapping so the namespace_stackable key
  is resolved at load time instead of on every callback definition.
- routing: replace `*args` + `args.first || ['/']` with a proper
  default-arg signature (`path = '/'`), removing the splat allocation
  and array-of-arrays default.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ericproulx ericproulx force-pushed the refactor/define-method-cleanup branch from 244cbb9 to 05b997c Compare May 14, 2026 08:38
@dblock dblock merged commit 028e703 into master May 14, 2026
79 checks passed
@dblock dblock deleted the refactor/define-method-cleanup branch May 14, 2026 16:35
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