summaryrefslogtreecommitdiff
path: root/lib/chef/node
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef/node')
-rw-r--r--lib/chef/node/attribute.rb9
-rw-r--r--lib/chef/node/common_api.rb6
2 files changed, 15 insertions, 0 deletions
diff --git a/lib/chef/node/attribute.rb b/lib/chef/node/attribute.rb
index eac867899c..2fc5d55a8e 100644
--- a/lib/chef/node/attribute.rb
+++ b/lib/chef/node/attribute.rb
@@ -341,6 +341,7 @@ class Chef
def with_deep_merged_return_value(obj, *path, last)
hash = obj.read(*path)
return nil unless hash.is_a?(Hash)
+
ret = hash[last]
yield
ret
@@ -357,6 +358,7 @@ class Chef
# - this API autovivifies (and cannot trainwreck)
def default!(*args)
return Decorator::Unchain.new(self, :default!) unless args.length > 0
+
write(:default, *args)
end
@@ -365,6 +367,7 @@ class Chef
# - this API autovivifies (and cannot trainwreck)
def normal!(*args)
return Decorator::Unchain.new(self, :normal!) unless args.length > 0
+
write(:normal, *args)
end
@@ -373,6 +376,7 @@ class Chef
# - this API autovivifies (and cannot trainwreck)
def override!(*args)
return Decorator::Unchain.new(self, :override!) unless args.length > 0
+
write(:override, *args)
end
@@ -381,6 +385,7 @@ class Chef
# - this API autovivifies (and cannot trainwreck)
def force_default!(*args)
return Decorator::Unchain.new(self, :force_default!) unless args.length > 0
+
value = args.pop
rm_default(*args)
write(:force_default, *args, value)
@@ -389,6 +394,7 @@ class Chef
# clears from all override precedence levels and then sets force_override
def force_override!(*args)
return Decorator::Unchain.new(self, :force_override!) unless args.length > 0
+
value = args.pop
rm_override(*args)
write(:force_override, *args, value)
@@ -417,16 +423,19 @@ class Chef
def normal_unless(*args)
return Decorator::Unchain.new(self, :normal_unless) unless args.length > 0
+
write(:normal, *args) if normal.read(*args[0...-1]).nil?
end
def default_unless(*args)
return Decorator::Unchain.new(self, :default_unless) unless args.length > 0
+
write(:default, *args) if default.read(*args[0...-1]).nil?
end
def override_unless(*args)
return Decorator::Unchain.new(self, :override_unless) unless args.length > 0
+
write(:override, *args) if override.read(*args[0...-1]).nil?
end
diff --git a/lib/chef/node/common_api.rb b/lib/chef/node/common_api.rb
index a703c1ef54..229103556b 100644
--- a/lib/chef/node/common_api.rb
+++ b/lib/chef/node/common_api.rb
@@ -59,9 +59,11 @@ class Chef
last = args.pop
obj = args.inject(self) do |memo, key|
raise Chef::Exceptions::AttributeTypeMismatch unless valid_container?(memo, key)
+
memo[key]
end
raise Chef::Exceptions::AttributeTypeMismatch unless valid_container?(obj, last)
+
obj[last] = value
end
@@ -71,6 +73,7 @@ class Chef
def exist?(*path)
path.inject(self) do |memo, key|
return false unless valid_container?(memo, key)
+
if memo.is_a?(Hash)
if memo.key?(key)
memo[key]
@@ -98,6 +101,7 @@ class Chef
# non-autovivifying reader that throws an exception if the attribute does not exist
def read!(*path)
raise Chef::Exceptions::NoSuchAttribute unless exist?(*path)
+
path.inject(self) do |memo, key|
memo[key]
end
@@ -108,11 +112,13 @@ class Chef
def unlink(*path, last)
hash = path.empty? ? self : read(*path)
return nil unless hash.is_a?(Hash) || hash.is_a?(Array)
+
hash.delete(last)
end
def unlink!(*path)
raise Chef::Exceptions::NoSuchAttribute unless exist?(*path)
+
unlink(*path)
end