Repository navigation
Define InheritableSetting's scalar settings and scope flags by key - #3031
Merged
Merged
Conversation
ericproulx
force-pushed
the
refactor/inheritable-setting-accessors
branch
from
October 10, 2026 23:22
c45770c to
1208fe5
Compare
Danger ReportNo issues found. |
ericproulx
force-pushed
the
refactor/inheritable-setting-accessors
branch
from
October 10, 2026 23:26
1208fe5 to
d083798
Compare
dblock
requested changes
Oct 12, 2026
dblock
left a comment
Member
There was a problem hiding this comment.
The Ruby way of doing this is a DSL, declare something like inheritable_property, then use it like inheritable_property :auth.
ericproulx
force-pushed
the
refactor/inheritable-setting-accessors
branch
2 times, most recently
from
October 16, 2026 18:46
a531033 to
203b73a
Compare
Contributor
Author
|
Thanks @dblock, done: |
ericproulx
force-pushed
the
refactor/inheritable-setting-accessors
branch
4 times, most recently
from
October 17, 2026 19:28
18969d7 to
feb7195
Compare
Ten nearest-wins settings were each a hand-written reader calling inheritable(key) and a writer calling set_inheritable(key, value), and four scope flags each a bang method and a predicate built the same way: 28 methods, all the same two bodies with a different key. Two private class macros now declare them: inheritable_property defines the reader and writer of each key it is given, inheritable_flag the bang method and predicate. Each group of keys is declared under the comment it had before, and the shared contract is documented once on the macro. cascade_defined?, the rescue handler readers and the stackable registrations keep their own methods, since each differs from these. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ericproulx
force-pushed
the
refactor/inheritable-setting-accessors
branch
from
October 17, 2026 20:42
feb7195 to
5556220
Compare
dblock
approved these changes
Oct 19, 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.
Grape::Util::InheritableSettinghand-wrote 28 methods that differ only in their key:format,default_format,default_error_formatter,default_error_status,version,version_options,root_prefix,cascade,build_params_with,auth), each a reader callinginheritable(key)and a writer callingset_inheritable(key, value);do_not_route_head,do_not_route_options,do_not_document,lint), each akey!settingtrueand akey?comparing withtrue.Change
Two private class macros declare them:
and the declarations sit together, the properties first, then the flags:
=writer rather thanadd_*, nil or false when never set) is documented once on its macro.private_class_method, as inUtil::MediaType), so the class's public surface is unchanged.cascade_defined?, the rescue handler readers (each set together with other keys by itsadd_*writer) and the stackable registrations keep their own methods.InheritableSettingis 359 lines byMetrics/ClassLength. The limit stays at 425; Keep a logger set on one API from replacing every other API's #3024 raises it, so it can come down once both are in.Equivalence
A script dumped on master and on this branch: public, protected and private instance methods; the class's own public methods; each accessor's arity; writer and bang return values; inheritance through a parent; an explicit
nilshadowing an inherited value; andArgumentErroron a reader given an argument. The dumps are identical.Tests
No spec changes.
bundle exec rakepasses. Mutation-checked through the generated methods: a reader that ignores the parent chain fails 87 examples, a writer that stores nothing 656, a predicate stuck atfalse12.Performance
define_methodmethods cost a little more per call thandefin the interpreter. Ruby 4.0.7, master and this branch run alternately:error!(readsdefault_error_status), interpreter, 4 roundsThe request and build rows are within their ±2–5% run-to-run error. The
error!interpreter rounds ranged from −3.3% to +2.8%.With #3024
#3024 adds a hand-written
logger/logger=pair. Whichever lands second should replace it withinheritable_property :loggerunder its comment.🤖 Generated with Claude Code