Remove Grape::Util::InheritableValues, resolving inheritable settings by walking parent#2830
Open
ericproulx wants to merge 2 commits into
Open
Remove Grape::Util::InheritableValues, resolving inheritable settings by walking parent#2830ericproulx wants to merge 2 commits into
ericproulx wants to merge 2 commits into
Conversation
InheritableValues layers a scope's own values over an enclosing scope's, but nothing ever gave @namespace an enclosing scope to layer over: #inherit_from assigns inherited_values only to @namespace_inheritable. Namespace settings are scope-local by design — a nested namespace must not see the outer one's value, which DSL::Settings#namespace_setting is specified to do — so the layering resolved nothing and the store was a Hash with extra indirection. Keep it as a Hash. #namespace_setting reads and writes through #[] and #[]= either way, so the DSL is unaffected. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Each InheritableSetting held an InheritableValues layered over the store of the scope it inherited from, so the parent relationship was encoded twice: once as @parent, once as that chain, kept in sync by #inherit_from. Two representations of one fact is the shape that produced #2794, where handlers were written to and read from different stores. Keep a scope's own overrides in a plain Hash — nil until first write, like @stackable_values — and resolve reads against #parent, the same move StackableValues got in #2823. InheritableValues then has nothing left to do and is removed, along with its unreachable #merge and #delete. Resolution is unchanged: reads key off presence rather than truthiness, so a scope can still override an inherited value with an explicit nil (#cascade relies on this), #inheritable? still reports an assignment made anywhere along the chain, and the chain stays live, so a value an enclosing scope gains later is visible through scopes already nested inside it. The deleted class's spec is replaced by coverage of those invariants through InheritableSetting's own API, where they were previously untested. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
ericproulx
force-pushed
the
remove-inheritable-values
branch
from
July 26, 2026 20:17
6cdf766 to
3d0d87a
Compare
Danger ReportNo issues found. |
dblock
approved these changes
Jul 27, 2026
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.
Follows #2823, which moved stackable storage onto
Grape::Util::InheritableSettingand leftStackableValuesa read-only view. This does the same for the inheritable scalars, in two commits.1. Store namespace settings in a plain Hash
InheritableValueslayers a scope's own values over an enclosing scope's — but nothing ever gave@namespacean enclosing scope to layer over.#inherit_fromassignsinherited_valuesto@namespace_inheritableonly, so@namespace's stayed{}for the object's whole life.That isn't an oversight: namespace settings are scope-local by design, and
spec/grape/dsl/settings_spec.rb:48pins that a nested namespace must not see the outer one's value. So the layering resolved nothing and the store was a Hash with extra indirection.#namespace_settingreads and writes through#[]/#[]=either way, so the DSL is untouched.2. Resolve inheritable settings by walking
parentThe parent relationship was encoded twice — once as
@parent, once as theinherited_valueschain — and#inherit_fromhad to keep them in sync. Two representations of one fact is the shape that produced #2794, where rescue handlers were written to and read from different stores.A scope now keeps only its own overrides, in a Hash that stays
niluntil the first write (like@stackable_values), and reads resolve against#parent:with
#inheritable?for the presence predicate behindcascade_defined?and#inheritable_valuesfor the merged view#to_hashneeds — mirroring#stacked/#stacked_keys. The 39@namespace_inheritable[...]call sites becomeinheritable(:key)/set_inheritable(:key, value).InheritableValuesthen has nothing left to do and is removed, along with its#mergeand#delete, which had no caller inlib/(#mergedoubly so — it merged into a throwaway copy and discarded the result).Behavior preserved
Three invariants carry the risk here, and all three are unchanged:
nil—#cascadedocuments and depends on this, and a||-based walk would silently break it.cascade_defined?still reports an assignment made by any enclosing scope, including one that assignednil.point_in_time_copyand re-parenting rely on.Tests
The deleted class's spec is replaced by coverage of those invariants through
InheritableSetting's own API — where, notably, they were previously untested: nothing exercisedcascade_defined?or thenil-override rule. I checked the new specs earn their place by running them against a naive truthiness-based#inheritable; thenil-override example fails as intended.Suite green throughout (2458 examples: 2462 − 9 deleted
InheritableValuesexamples + 5 new), and green at commit 1 alone (2462) so the two are independently bisectable.Metrics/ClassLength395 → 410.Note on #2828
The
inheritable-setting-cheap-equalitywork addsInheritableValues#==and calls it "the actual blocker, since it defined no equality and every copy is a distinct object". With plain Hashes that method is unnecessary —Hash#==is free — so if this lands first, that branch loses a moving part rather than gaining a conflict.🤖 Generated with Claude Code