puppetlabs/hiera — pull request #100 by justenwalker (2012-10-19 20:13:42+00:00)
Title: New Feature - Support deep hash merges

# Problem

Hiera uses Ruby's default Hash#merge method to merge result sets for each back end.
This is a shallow merge and does not account for nested hashes and arrays.

# Proposed Solution

Specify an optional dependency on the 'deep_merge' gem which provides deep
merge semantics for hashes.

# Notes

The default merge behavior will not change without explicitly defining :merge_behavior:
```yaml
:hierarchy:
- yaml
- json

:merge_behavior: deep
```

It should be backwards compatible with existing hiera installations and 3rd-party backends
since the defaults leave the existing behavior the same.

3rd party backends can take advantage of this easily by changing their lookup code:

```ruby
new_answer = Backend.parse_answer(data[key], scope)

case resolution_type
# ...

when :hash
answer ||= {}
# Old Method:
# answer = new_answer.merge(answer)
answer = Backend.merge_answer( new_answer, answer )
else
# ...
end
```

# Changelog
- Config option :merge_behavior => :native|:deep|:deeper
- Add optional requirement on deep_merge gem to support
:deep and :deeper options
- Update Yaml backend to use Backend.merge_answer
- Update Json backend to use Backend.merge_answer