Values::ArgumentError - exception class containing missing/unexpected constructor arguments#51
Open
tomeon wants to merge 2 commits intotom-pang:masterfrom
Open
Values::ArgumentError - exception class containing missing/unexpected constructor arguments#51tomeon wants to merge 2 commits intotom-pang:masterfrom
tomeon wants to merge 2 commits intotom-pang:masterfrom
Conversation
…ed keys in initialize()
Owner
|
@BaxterStockman whilst I agree on Values' small size, I like this PR and would like to merge it. I have some nitpicks that I'd like addressed first. |
lib/values.rb
Outdated
1. {missing,unexpected}_keys => {missing,unexpected}_values
2. Values::ArgumentError => Values::FieldError
3. Default values for @{missing,unexpected}_fields now [] instead of nil
Author
|
@tcrayford -- many thanks for your feedback! I've updated the PR in response to your comments. |
Contributor
|
@tcrayford -- are you planning to merge this and release a 1.10.0? |
Contributor
|
ping |
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.
I hesitate to make this PR given that part of Values' appeal is its exceptionally small size; so, apologies in advance if the changeset it unwanted, and thanks for taking the time to review it.
I use Values for input validation and would find it helpful if the exceptions raised by the
.newand.withmethods upon receipt of bad arguments contained lists of missing and unrecognized keys, along the same lines as how virtus'sCoercionErrorexception class has the.attribute_namemethod for helping to determine which failed attribute prevented an object's instantiation.Since Values already validates constructor arguments, this PR mostly amounts to percolating existing data up to the caller -- the exception being the second argument to the
Values::ArgumentErrorcreated in.new.The convention I've followed is that the
@missing_keysand@unexpected_keysattributes will contain empty arrays if there were, respectively, no missing arguments or no extra arguments to.with. By contrast,@unexpected_keyswill benilif there were extra arguments provided to.new, since there is no way to determine the 'meaning' of additional positional parameters in the absence of handy hash keys acting a labels.