Remove Grape::Util::ReverseStackableValues#2796
Merged
Merged
Conversation
Since #2795 internalized namespace_reverse_stackable into InheritableSetting, ReverseStackableValues had a single consumer holding exactly two keys (rescue_handlers / base_only_rescue_handlers). Its only job was reverse-order chain traversal, but InheritableSetting already tracks the same chain through #parent. Replace the store with a plain per-scope Hash of rescue_from registrations and merge it recursively over #parent. Hash#merge natively yields the ordering Middleware::Error's find-based scan depends on: the nearest scope's keys first (registration order preserved within a scope), inherited keys appended, nearer handler winning on collision. InheritableSetting#to_hash now exposes the merged rescue_handlers / base_only_rescue_handlers instead of a namespace_reverse_stackable key. Also drops the per-layer ReverseStackableValues allocation and the intermediate arrays StackableValues#[] built on every read. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
d69e812 to
b03ffa2
Compare
Danger ReportNo issues found. |
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.
Since #2795 internalized
namespace_reverse_stackableintoInheritableSetting,Grape::Util::ReverseStackableValueshad a single consumer holding exactly two keys (rescue_handlers/base_only_rescue_handlers). Its only remaining job was reverse-order chain traversal — butInheritableSettingalready tracks the same chain through#parent, so the class was a second way of walking a chain the setting has a pointer to.This removes the class (and its spec) and replaces the store with a plain per-scope Hash of
rescue_fromregistrations, merged recursively over#parent:Hash#mergenatively yields the orderingMiddleware::Error'sfind-based scan depends on: the nearest scope's keys first (registration order preserved within a scope), inherited keys appended, nearer handler winning on collision. Behavior is unchanged, including the mounted-app specificity cases (prefers rescues defined by mounted even if outer is more specific) and same-scope ordering (rescue_from ArgumentErrorbeforerescue_from StandardError).Side effects:
InheritableSetting#to_hashnow exposesrescue_handlers/base_only_rescue_handlers(the merged view callers actually consume) instead of anamespace_reverse_stackablekey.rescue_fromno longer carry aReverseStackableValuesinstance, and reads no longer build the intermediate arraysStackableValues#[]allocated per chain level.🤖 Generated with Claude Code