Skip to content

Commit

Permalink
Merge config recursively
Browse files Browse the repository at this point in the history
  • Loading branch information
gpakosz committed May 7, 2017
1 parent 0fdea40 commit 2764c11
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/nanoc/base/entities/configuration.rb
Expand Up @@ -106,9 +106,14 @@ def []=(key, value)
@wrapped[key] = value
end

def merge_recursively(c1, c2)
c1.merge(c2) { |_, i1, i2| i1.is_a?(Hash) && i2.is_a?(Hash) ? merge_recursively(i1, i2) : i2 }
end
private :merge_recursively

contract C::Or[Hash, self] => self
def merge(hash)
self.class.new(hash: @wrapped.merge(hash.to_h), env_name: @env_name)
self.class.new(hash: merge_recursively(@wrapped, hash.to_h), env_name: @env_name)
end

contract C::Any => self
Expand Down

0 comments on commit 2764c11

Please sign in to comment.