Move content-type helpers from Middleware::Base into PrecomputedContentTypes#2719
Open
ericproulx wants to merge 1 commit into
Open
Move content-type helpers from Middleware::Base into PrecomputedContentTypes#2719ericproulx wants to merge 1 commit into
ericproulx wants to merge 1 commit into
Conversation
…ntTypes `Middleware::Base#content_types` / `#mime_types` / `#content_type_for` / `#content_type` / `#content_types_indifferent_access` are only consumed by middleware that include `PrecomputedContentTypes` — namely `Formatter`, `Error`, and `Versioner::Base`. The other concrete middlewares (`Filter`, `Auth::Base`) never call them. Move the five methods into `PrecomputedContentTypes`. `Base` keeps the ivar plumbing (`@options`, `@env`, `@app`), `Rack::Request` wrapper, header merge, and `query_params`; the content-type concern lives with the mixin that already takes responsibility for warming its caches. This narrows `Base` to the storage / lifecycle layer and unblocks future work to give per-middleware `Options` value objects without `Base` reaching back into the option hash. No behaviour change — every middleware that called those helpers already included `PrecomputedContentTypes`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
51f7cc2 to
2532013
Compare
Danger ReportNo issues found. |
3 tasks
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.
Summary
Middleware::Base#content_types/#mime_types/#content_type_for/#content_type/#content_types_indifferent_accessare only consumed by middleware thatinclude Grape::Middleware::PrecomputedContentTypes— namelyFormatter,Error, andVersioner::Base. The other concrete middlewares (Filter,Auth::Base) never call them.Move the five methods into
PrecomputedContentTypes.Basekeeps the storage layer (@options/@env/@app/Rack::Requestwrapper / header merge /query_params); the content-type concern lives with the mixin that already takes responsibility for warming its caches.Why
Currently
Basereaches into the options Hash twice —options[:content_types]andoptions[:format]— to compute helpers that not every subclass needs. That coupling makes it impossible to migrate a subclass's options to a typed value object without also retrofitting Hash semantics onto that value object, just to keepBasehappy.After this move,
Basedoesn't touch its options hash at all. The mixin still usesoptions[:…]— but now only middleware that opted in by including the mixin pay for that coupling, and a follow-up can replace the[]access inside the mixin without rippling throughBase.Scope
lib/grape/middleware/base.rb— five methods removed.lib/grape/middleware/precomputed_content_types.rb— same five methods added, identical bodies, ivar caching preserved.No call sites moved or renamed;
PrecomputedContentTypesis currentlyincluded in exactly the three middlewares that called these helpers, so behaviour is unchanged.Test plan
bundle exec rspec— 2307 examples, 0 failures🤖 Generated with Claude Code