lib/hieracles/node.rb in hieracles-0.1.5 vs lib/hieracles/node.rb in hieracles-0.1.6

- old
+ new

@@ -1,8 +1,9 @@ require "net/http" require "uri" require "yaml" +require 'deep_merge' module Hieracles class Node include Hieracles::Utils include Hieracles::Interpolate @@ -45,11 +46,11 @@ files(without_common).map { |p| File.join(Config.basepath, p) } end def params(without_common = true) params = {} - files(without_common).each do |f| + files(without_common).reverse.each do |f| data = YAML.load_file(File.join(Config.basepath, f)) if data s = to_shallow_hash(data) s.each do |k,v| params[k] ||= [] @@ -61,16 +62,13 @@ params.sort end def params_tree(without_common = true) params = {} - paths(without_common).each do |f| - data = YAML.load_file(f) - if data - # data needs interpolation - deep_merge!(params, data) - end + paths(without_common).reverse.each do |f| + data = YAML.load_file(f) || {} + merge_trees params, data end deep_sort(params) end def modules @@ -112,9 +110,20 @@ else modules[mod] = nil end end modules + end + + def merge_trees(left, right) + case @hiera.merge_behavior + when :deeper + left.deep_merge!(right) + when :deep + left.deep_merge(right) + else # Native and undefined + local_merge!(left, right) + end end end end