summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-12-11 16:24:05 -0800
committerJohn Keiser <john@johnkeiser.com>2015-12-11 16:35:00 -0800
commit7a4acfe7c888bc56c9b33806da766eb2cc682c2d (patch)
tree10e739094567d165d29d3c2fd9dbd9a13bcc0e70 /lib
parent7814a405d629b612cd0b93266db79e2427f59d7d (diff)
downloadchef-jk/warn-less-on-nil.tar.gz
Don't warn when setting a property to nil unless its value wouldjk/warn-less-on-nil
actually change. Gets rid of cases where we are initializing a resource with values from another resource.
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/property.rb19
1 files changed, 11 insertions, 8 deletions
diff --git a/lib/chef/property.rb b/lib/chef/property.rb
index b2658235f2..742eba42fd 100644
--- a/lib/chef/property.rb
+++ b/lib/chef/property.rb
@@ -251,16 +251,19 @@ class Chef
return get(resource)
end
- # myprop nil is sometimes a get (backcompat)
if value.nil? && !explicitly_accepts_nil?(resource)
- # If you say "my_property nil" and the property explicitly accepts
- # nil values, we consider this a get.
- Chef.log_deprecation("#{name} nil currently does not overwrite the value of #{name}. This will change in Chef 13, and the value will be set to nil instead. Please change your code to explicitly accept nil using \"property :#{name}, [MyType, nil]\", or stop setting this value to nil.")
- return get(resource)
+ # In Chef 12, value(nil) does a *get* instead of a set, so we
+ # warn if the value would have been changed. In Chef 13, it will be
+ # equivalent to value = nil.
+ result = get(resource)
+ if !result.nil?
+ Chef.log_deprecation("#{name} nil currently does not overwrite the value of #{name}. This will change in Chef 13, and the value will be set to nil instead. Please change your code to explicitly accept nil using \"property :#{name}, [MyType, nil]\", or stop setting this value to nil.")
+ end
+ result
+ else
+ # Anything else, such as myprop(value) is a set
+ set(resource, value)
end
-
- # Anything else (myprop value) is a set
- set(resource, value)
end
#