summaryrefslogtreecommitdiff
path: root/lib/chef/property.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef/property.rb')
-rw-r--r--lib/chef/property.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/chef/property.rb b/lib/chef/property.rb
index c36daa821a..45ab4dd522 100644
--- a/lib/chef/property.rb
+++ b/lib/chef/property.rb
@@ -72,6 +72,9 @@ class Chef
# property defaults to the same value as `name`. Equivalent to
# `default: lazy { name }`, except that #property_is_set? will
# return `true` if the property is set *or* if `name` is set.
+ # @option options [Boolean] :nillable `true` opt-in to Chef-13 style behavior where
+ # attempting to set a nil value will really set a nil value instead of issuing
+ # a warning and operating like a getter
# @option options [Object] :default The value this property
# will return if the user does not set one. If this is `lazy`, it will
# be run in the context of the instance (and able to access other
@@ -233,7 +236,7 @@ class Chef
#
def validation_options
@validation_options ||= options.reject { |k, v|
- [:declared_in, :name, :instance_variable_name, :desired_state, :identity, :default, :name_property, :coerce, :required].include?(k)
+ [:declared_in, :name, :instance_variable_name, :desired_state, :identity, :default, :name_property, :coerce, :required, :nillable].include?(k)
}
end
@@ -262,7 +265,7 @@ class Chef
return get(resource)
end
- if value.nil?
+ if value.nil? && !nillable?
# 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.
@@ -670,5 +673,9 @@ class Chef
result
end
+
+ def nillable?
+ !!options[:nillable]
+ end
end
end