[chef-dev] deep_merge! weirdness


Chronological Thread 
  • From: Avishai Ish-Shalom < >
  • To: Chef Dev < >
  • Subject: [chef-dev] deep_merge! weirdness
  • Date: Sun, 13 Oct 2013 23:49:59 +0200

i came across something i'm unsure about in deep_merge!. it seems that when merging hash deep_merge! will re-assign dest source.length times if dest is not a hash. i've patched this and specs are green, but i wonder if i'm missing something.

--- a/lib/chef/mixin/deep_merge.rb
+++ b/lib/chef/mixin/deep_merge.rb
@@ -84,17 +84,17 @@ class Chef
         when nil
           dest
         when Hash
-          source.each do |src_key, src_value|
-            if dest.kind_of?(Hash)
+          if dest.kind_of?(Hash)
+            source.each do |src_key, src_value|
               if dest[src_key]
                 dest[src_key] = deep_merge!(src_value, dest[src_key])
               else # dest[src_key] doesn't exist so we take whatever source has
                 raise_if_knockout_used!(src_value)
                 dest[src_key] = src_value
               end
-            else # dest isn't a hash, so we overwrite it completely
-              dest = source
             end
+          else # dest isn't a hash, so we overwrite it completely
+            dest = source
           end
         when Array
           if dest.kind_of?(Array)



Archive powered by MHonArc 2.6.16.

§