summaryrefslogtreecommitdiff
path: root/lib/chef/property.rb
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-10-08 20:24:55 -0700
committerJohn Keiser <john@johnkeiser.com>2015-10-08 20:25:47 -0700
commitc9473b61e7d5f6f48598acaef4af0cfdf821f579 (patch)
treec4ab7ac6ddc1748bfb049693fae1f234432d2d04 /lib/chef/property.rb
parent56b3c90bbd7c4657533b99d04dcdc3419dcd472b (diff)
downloadchef-c9473b61e7d5f6f48598acaef4af0cfdf821f579.tar.gz
Accept coercion as a way to accept nil values
Diffstat (limited to 'lib/chef/property.rb')
-rw-r--r--lib/chef/property.rb5
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/chef/property.rb b/lib/chef/property.rb
index c1207d9132..e97d8f9607 100644
--- a/lib/chef/property.rb
+++ b/lib/chef/property.rb
@@ -479,6 +479,8 @@ class Chef
# A type accepts nil explicitly if "is" allows nil, it validates as nil, *and* is not simply
# an empty type.
#
+ # A type is presumed to accept nil if it does coercion (which must handle nil).
+ #
# These examples accept nil explicitly:
# ```ruby
# property :a, [ String, nil ]
@@ -510,7 +512,8 @@ class Chef
#
# @api private
def explicitly_accepts_nil?(resource)
- options.has_key?(:is) && resource.send(:_pv_is, { name => nil }, name, options[:is], raise_error: false)
+ options.has_key?(:coerce) ||
+ (options.has_key?(:is) && resource.send(:_pv_is, { name => nil }, name, options[:is], raise_error: false))
end
def get_value(resource)