diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2018-11-07 14:06:07 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2018-11-09 14:17:09 -0800 |
commit | f827907b83b3c4a55200ebdf2f89882bc1f3736a (patch) | |
tree | 11a1b38b3510ce9a01207e66411dcf308886e1d8 /lib/chef/node/attribute.rb | |
parent | 156e91bff63f275884ff6ddcb70ab49a05c7270d (diff) | |
download | chef-f827907b83b3c4a55200ebdf2f89882bc1f3736a.tar.gz |
Chef-15: add nillability to attribute deep merging
Changes to consistently uses the "NIL" object internally to mean "not present"
instead of abusing nil for that purpose.
So now "nil means nil" and we can deep merge that so it will effectively
override lower precedence levels if you write a nil.
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef/node/attribute.rb')
-rw-r--r-- | lib/chef/node/attribute.rb | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/chef/node/attribute.rb b/lib/chef/node/attribute.rb index 69cb327d70..d0808cfa34 100644 --- a/lib/chef/node/attribute.rb +++ b/lib/chef/node/attribute.rb @@ -406,11 +406,13 @@ class Chef end def combined_override(*path) - merge_overrides(path) + ret = merge_overrides(path) + ret == NIL ? nil : ret end def combined_default(*path) - merge_defaults(path) + ret = merge_defaults(path) + ret == NIL ? nil : ret end def normal_unless(*args) @@ -505,10 +507,10 @@ class Chef # Hash-like thing (must check has_key? first to protect against Autovivification) val[path_arg] else - nil + NIL end else - nil + NIL end end end @@ -552,7 +554,7 @@ class Chef component_value = apply_path(instance_variable_get(component_ivar), path) deep_merge!(merged, component_value) end - ret == NIL ? nil : ret + ret end # Deep merge the override attribute levels with array merging. @@ -566,7 +568,7 @@ class Chef component_value = apply_path(instance_variable_get(component_ivar), path) deep_merge!(merged, component_value) end - ret == NIL ? nil : ret + ret end # needed for __path__ @@ -597,7 +599,7 @@ class Chef merge_onto |= merge_with # If merge_with is nil, don't replace merge_onto - elsif merge_with.nil? + elsif merge_with == NIL merge_onto # In all other cases, replace merge_onto with merge_with @@ -630,7 +632,7 @@ class Chef merge_onto # If merge_with is nil, don't replace merge_onto - elsif merge_with.nil? + elsif merge_with == NIL merge_onto # In all other cases, replace merge_onto with merge_with |