Use an internal Grape::Validations::SharedOptions value object#2721
Open
ericproulx wants to merge 1 commit into
Open
Use an internal Grape::Validations::SharedOptions value object#2721ericproulx wants to merge 1 commit into
ericproulx wants to merge 1 commit into
Conversation
304266f to
28395d2
Compare
Danger ReportNo issues found. |
Danger ReportNo issues found. |
28395d2 to
d70bf23
Compare
`Validators::Base#initialize` consumed the shared `opts` via `opts.values_at(:fail_fast, :allow_blank)` and copied the two values into per-validator ivars. Introduce `Grape::Validations::SharedOptions` (`Data.define(:allow_blank, :fail_fast)` with defaults mirroring the prior `values_at` behaviour) as an *internal* representation: `Base` builds it from the `opts` Hash — `SharedOptions.new(**opts.slice(:allow_blank, :fail_fast))` — and exposes the two fields via `Forwardable.def_delegators :@opts, :allow_blank, :fail_fast`. `#fail_fast?` calls the delegated `fail_fast`; `ValuesValidator` (the one subclass reading `@allow_blank` directly) uses the `allow_blank` reader. The public 5th-argument contract of `Validators::Base#initialize` stays a plain Hash, so custom validators and any code that hand-constructs a validator with a Hash are unaffected. `slice` keeps the historical tolerance of ignoring unknown keys. `ValidationsSpec` keeps emitting the `{ allow_blank:, fail_fast: }.freeze` Hash; nothing about its public surface changes — no UPGRADING entry needed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
d70bf23 to
ae11328
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.
Summary
Validators::Base#initializeconsumed the sharedoptsviaopts.values_at(:fail_fast, :allow_blank)and copied both into per-validator ivars (@fail_fast/@allow_blank), withValuesValidatorreaching into@allow_blankdirectly.Introduce
Grape::Validations::SharedOptions—Data.define(:allow_blank, :fail_fast)with defaults mirroring the priorvalues_atbehaviour — as a purely internal representation:and expose the fields via
extend Forwardable; def_delegators :@opts, :allow_blank, :fail_fast.#fail_fast?delegates;ValuesValidatorswitches to theallow_blankreader.No contract change
The public 5th argument of
Validators::Base#initializestays a plain Hash. The Hash → value-object conversion happens insideBase, so:superthe args through — unaffected.opts.slice(:allow_blank, :fail_fast)preserves the historical tolerance of silently ignoring any other keys (matching the oldvalues_at).ValidationsSpec#shared_optskeeps emitting the frozen{ allow_blank:, fail_fast: }Hash — its (internal) surface is unchanged.No
UPGRADING.mdentry needed — there is no behaviour or contract change, just an internal cleanup that removes the scattered ivars in favour of one delegated value object.Test plan
bundle exec rspec— 2307 examples, 0 failureslib/grape/validations/🤖 Generated with Claude Code