-
Notifications
You must be signed in to change notification settings - Fork 310
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
Add blacklisted warnings #478
Add blacklisted warnings #478
Conversation
e248f53
to
ad523c8
Compare
Why do we need the I feel like |
@dblock I suppose we don't explicitly need the |
lib/hashie/mash.rb
Outdated
@@ -59,7 +59,7 @@ module Hashie | |||
# mash.author_.name = "Michael Bleigh" (assigned to temp object) | |||
# mash.author # => <Mash> | |||
# | |||
class Mash < Hash | |||
class Mash < Hash # rubocop:disable Metrics/ClassLength |
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.
For rubocop just run rubocop -a ; rubocop --auto-gen-config
. Or just disable Metrics/ClassLength altogether in .rubocop_config.yml.
I think the behavior when both variations are used is broken here. I'd expect these to pass: it 'does not write to the logger when warnings are disabled' do
mash_class = Class.new(Hashie::Mash) do
disable_warnings :zip
disable_warnings
end
mash_class.new('trust' => { 'two' => 2 })
expect(logger_output).to be_blank
end and this one when using an array it 'has cumulative behavior' do
mash_class = Class.new(Hashie::Mash) do
disable_warnings :two, :zip
end
mash_class.new('trust' => { 'two' => 2 })
mash_class.new('address' => { 'zip' => '90210' })
expect(logger_output).to be_blank
end |
it 'has cumulative behavior' do
mash_class = Class.new(Hashie::Mash) do
disable_warnings :two, :zip
end
mash_class.new('trust' => { 'two' => 2 })
mash_class.new('address' => { 'zip' => '90210' })
expect(logger_output).to be_blank
end This scenario works for the given keys, the error being I'll give some thoughts to the other scenario you mentioned. |
After looking at my test, the case where a child calls Now when |
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 like the implementation but I think we can get away with fewer lines of added code by changing the implementation of the disable_warnings?
predicate.
I am happy with this with the minor fixes in my last comments. @BobbyMcWho you should squash your commits, leaving the final review/comments/merge to @michaelherold. |
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.
This is looking really good! I'd like to see a little more documentation in the readme and dB's typo fix, otherwise we're good-to-go.
Use keyword arg instead of opts Rubocop fixes Uniq the blacklist Add only arg for disable_warnings Add Hashie::Mash.disable_warnings parameter Remove :only keyword Add array parameter Mash.disable_warnings Allows for only ignoring specific warnings Latest called disable_warnings takes priority When called in succession, disable_warnings with params will simply append to the blacklist. If called without params, we clear the blacklist and simply ignore all errors. Change disable_warnings signature This will make various pieces of code much more readable and reduce some duplication. Additional multiple disable_warnings call specs fix typo Add additional disable_warnings documentation
359ac81
to
a17f96f
Compare
Thanks for the documentation suggestion @dblock, for the sake of clarity I also added: Disable warnings will honor the last class Message < Hashie::Mash
disable_warnings :zip, :zap
disable_warnings
end
# No errors will be logged
Message.new(merge: 'true', compact: true) class Message < Hashie::Mash
disable_warnings
end
class Response < Message
disable_warnings :zip, :zap
end
# 2 errors will be logged
Response.new(merge: 'true', compact: true, zip: '90210', zap: 'electric') |
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'm really happy with this now. I fixed up some spacing issues in the readme that I'll squash out once the tests pass.
Thanks a bunch for the contribution!
Thanks for all the input from both of you, it's been a pleasure! |
Nice work @BobbyMcWho, thanks for hanging in there with us! |
Adds an optional array parameter to the
disable_warnings
method, so that you can pick and choose which warnings to ignore.Usage:
This preserves existing usage.