-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
136 refactor value parser #143
base: main
Are you sure you want to change the base?
Changes from all commits
acb696c
b974b9c
9c59b11
086d452
2a9f417
1fbf568
161a77c
096e281
d8f7f0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module Decanter | ||
module Parser | ||
class PassParser < ValueParser | ||
class PassParser < Base | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment above |
||
|
||
parser do |val, options| | ||
next if (val.nil? || val == '') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,16 @@ | |
module Decanter | ||
module Parser | ||
class ValueParser < Base | ||
|
||
def self._parse(name, value, options={}) | ||
{ name => @parser.call(value, options) } | ||
self.validate_singularity(value) | ||
super(name, value, options) | ||
end | ||
|
||
private | ||
|
||
def self.validate_singularity(value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can / should we make this private? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think so. Done! |
||
raise Decanter::ParseError.new 'Expects a single value' if value.is_a? Array | ||
end | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Decanter | ||
VERSION = '4.0.4'.freeze | ||
VERSION = '4.0.5'.freeze | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to make PassParser inherit from Base so that it wouldn't throw an error when an array was passed to it. I then had to update this line to pass some specs that said all parsers must inherit from ValueParser.
I'm not totally clear on the purpose of PassParser, but it looks like it is used for values that should not be touched/transformed? If I'm understanding this correctly, it seems fine if it does not inherit from ValueParser and therefore does not run a check to ensure the passed value is not an array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible that the PassParser has a defect where it doesn't have that guard clause, but should.
This is from the existing README:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the tests below from the
pass_parser_spec
tests, it seemsPassParser
is intended to accept an array (which conflicts with that blurb from the README):I think the result described by the test seems right - I'd expect to be able to pass any value if I had marked the key as
:pass
in my decanter. If this is right, maybe the right move is to update the README to indicate PassParser allows arrays?Or, maybe the intended use for
PassParser
is to allow elements of an array to be any type (i.e.input :items, :array, parse_each: :pass
), in which case we would want PassParser to only allow a singular value. In that case, I could update the specs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭 The second option would be a breaking change