-
Notifications
You must be signed in to change notification settings - Fork 313
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
Calls readers only when a key exists for Mash#update #465
Conversation
c5c87b4
to
381343d
Compare
spec/hashie/mash_spec.rb
Outdated
@@ -1,5 +1,6 @@ | |||
require 'spec_helper' | |||
|
|||
# rubocop: disable Metrics/BlockLength |
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.
Run rubocop -a ; rubocop --auto-gen-config
instead.
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.
@dblock I have problems making this to work. The above changes some files but does not make the build to pass (see my last commit.)
d8929aa
to
a39add6
Compare
It looks like you ran Rubocop with a newer version than the one we lint with, which is why CI is failing. You can use |
@@ -209,7 +209,7 @@ def deep_merge(other_hash, &blk) | |||
def deep_update(other_hash, &blk) | |||
other_hash.each_pair do |k, v| | |||
key = convert_key(k) | |||
if regular_reader(key).is_a?(Mash) && v.is_a?(::Hash) | |||
if key?(key) && regular_reader(key).is_a?(Mash) && v.is_a?(::Hash) |
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.
Simple fix! Since I'm looking at the line, I feel like we should swap the order of the v.is_a?
check and the reader check, but that's not something we need to address in this PR.
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.
@laertispappas I know this is outside of the scope here, but care to make this change so we don't forget? It's a lot faster to do is_a?
than to invoke regular_reader
. Thanks.
6d4b57d
to
44009b4
Compare
@michaelherold thanks for the feedback. Running with bundle exec I get diffs on all files (see the last commit). It's getting really frustrating... |
Looks like a previous run added all those frozen literals, so you should undo that. Check that Otherwise get a clean branch, make sure to |
If you are still having trouble, I can pick the changes from here. LMK! |
44009b4
to
46c797c
Compare
@dblock okay skipping rubocop line length on specs saved me :) |
0948c65
to
269bc97
Compare
@laertispappas Try to squash this too. Not required but nice. |
269bc97
to
209f8af
Compare
@dblock Done. Thanks. |
I merged this. Care to take care of https://github.com/intridea/hashie/pull/465/files#r221469352 in a new PR? |
@dblock Thanks and I don't have a strong argument on this. But why? Personally I kind of have key value pairs in my head (note key first) instead of value key. So what would be the value / difference on the change? |
if key?(key) && regular_reader(key).is_a?(Mash) && v.is_a?(::Hash) vs. if v.is_a?(::Hash) && key?(key) && regular_reader(key).is_a?(Mash) Avoids calling an expensive method |
@dblock Ack thanks. Will follow with the reverse order. |
Addresses: #464
Checks if key is present in
deep_update
before calling any reader method. Calling a reader method will execute the default block and we now prevent it.