Repository navigation
Resolve a scope's request params in ParamsScope instead of the params DSL - #3028
Merged
Merged
Conversation
ericproulx
force-pushed
the
refactor/params-scope-resolution
branch
from
October 10, 2026 22:58
9355afa to
832ddd0
Compare
Danger ReportNo issues found. |
… DSL DSL::Parameters holds the methods a params block calls, but it also held what resolves a scope's params on every request: #params, #map_params and the EmptyOptionalValue placeholder. They read ParamsScope's state, the only class that includes the module, and ParamsScope's own #validated_params called the private #map_params across it; the validators and AttributesIterator named the placeholder as Grape::DSL::Parameters::EmptyOptionalValue. All three now live in ParamsScope, and the placeholder is ParamsScope::EmptyOptionalValue. AttributesIterator tests for it with equal?, as the validators do, rather than asking the element's ==. The #params examples that ran against a stub of the module now run against real scopes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ericproulx
force-pushed
the
refactor/params-scope-resolution
branch
from
October 11, 2026 08:26
832ddd0 to
aed52c6
Compare
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::DSL::Parametersholds the methods aparamsblock calls (requires,optional,given,use, …). It also held three things that run on every request to resolve a scope's params:#params, called by every validator, byAttributesIteratorand byParamsScope#meets_dependency?;#map_params, whichParamsScope#validated_paramscalled across the module boundary;EmptyOptionalValue, the placeholder for an Array element that left an optional scope out. The validators andAttributesIteratornamed it asGrape::DSL::Parameters::EmptyOptionalValue.All three read
ParamsScope's state (@parent,@element,@optional,@independent), andParamsScopeis the only class that includes the module.Change
#params,#map_paramsand the placeholder move toParamsScope, unchanged. The placeholder is nowGrape::Validations::ParamsScope::EmptyOptionalValue, documented where it is defined.AttributesIterator#skip?tests for it withequal?, as the validators do. It used to ask the element's==, which for a placeholder only identity can match.DSL::Parametersis left with the params DSL alone.Grape::DSL::Parameters::EmptyOptionalValuewas a public constant (since 1.5.1) but never documented. GitHub code search finds it only in Grape and its forks, so it is moved rather than aliased, as #3009 did with the attribute iterator subclasses. No UPGRADING entry.Tests
#paramsexamples indsl/parameters_spec.rbran against a stub of the module withelementandparentassigned by hand. They now run against real scopes inparams_scope_spec.rb, each nested scope captured from inside its own block. The stub loses its now-unusedelement/parentaccessors.libtoo, as a move should.map_params: each of the Hash, Array and fallback branches, and the root case, fails at least one ported example when broken.Performance
benchmark-ips on
API.call(env)for a POST with a 10-elementArrayblock holding an optional nestedHashscope, Ruby 4.0.7, master and this branch run alternately, mean of two rounds:Each run's error was ±2.3–4.2%, and the interpreter result flipped between rounds, so this is noise.
🤖 Generated with Claude Code