summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel DeLeo <dan@opscode.com>2010-02-08 14:15:44 -0800
committerDaniel DeLeo <dan@opscode.com>2010-02-08 14:15:44 -0800
commit97af179dc7dabb0a3929d7c354128b9b02592957 (patch)
tree0abf8c5f7fb9222610098080ff3910cf7f6ffcdb
parentec5a30a32c2776c5846ee73865cf053fca0f5878 (diff)
downloadchef-97af179dc7dabb0a3929d7c354128b9b02592957.tar.gz
no need to monkey patch Hash or Mash with deep_merge
We use Chef::Mixin::DeepMerge as a module function instead of calling the method on the Mash or Hash objects themselves, so no need to monkey patch the Mash or Hash classes.
-rw-r--r--chef/lib/chef/mixin/deep_merge.rb37
1 files changed, 5 insertions, 32 deletions
diff --git a/chef/lib/chef/mixin/deep_merge.rb b/chef/lib/chef/mixin/deep_merge.rb
index b7e21690d7..11a3fa3353 100644
--- a/chef/lib/chef/mixin/deep_merge.rb
+++ b/chef/lib/chef/mixin/deep_merge.rb
@@ -24,14 +24,12 @@
class Chef
module Mixin
- class DeepMerge
+ module DeepMerge
def self.merge(first, second)
- first = Mash.new(first).to_hash unless second.kind_of?(Mash)
- first = first.to_hash
- second = Mash.new(second).to_hash unless second.kind_of?(Mash)
- second = second.to_hash
+ first = Mash.new(first) unless first.kind_of?(Mash)
+ second = Mash.new(second) unless second.kind_of?(Mash)
- Mash.new(first.ko_deep_merge!(second, {:knockout_prefix => '!merge:'}))
+ DeepMerge.deep_merge!(second, first, {:knockout_prefix => "!merge:", :preserve_unmergeables => false})
end
class InvalidParameter < StandardError; end
@@ -219,33 +217,8 @@ class Chef
end
end
-
-
- module DeepMergeHash
- # ko_hash_merge! will merge and knockout elements prefixed with DEFAULT_FIELD_KNOCKOUT_PREFIX
- def ko_deep_merge!(source, options = {})
- default_opts = {:knockout_prefix => "--", :preserve_unmergeables => false}
- DeepMerge::deep_merge!(source, self, default_opts.merge(options))
- end
-
- # deep_merge! will merge and overwrite any unmergeables in destination hash
- def deep_merge!(source, options = {})
- default_opts = {:preserve_unmergeables => false}
- DeepMerge::deep_merge!(source, self, default_opts.merge(options))
- end
-
- # deep_merge will merge and skip any unmergeables in destination hash
- def deep_merge(source, options = {})
- default_opts = {:preserve_unmergeables => true}
- DeepMerge::deep_merge!(source, self, default_opts.merge(options))
- end
-
- end # DeepMergeHashExt
-
+
end
end
-class Hash
- include Chef::Mixin::DeepMergeHash
-end