diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2016-04-14 11:30:40 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2016-04-14 11:30:40 -0700 |
commit | 03503d7352ccad45107b055fc711e86c7c5d2918 (patch) | |
tree | 22b44530ad934d4846167021b2485abf45fb8110 /lib/chef/property.rb | |
parent | 95c13caaf4c8a20ba6d1f49680cd23de60cdb231 (diff) | |
download | chef-03503d7352ccad45107b055fc711e86c7c5d2918.tar.gz |
add nillable apt_repository and nillable properties
in Chef-13 nillable will become 'true' by default and we'll have
to deprecate and remove all nillable properties, but for now
this lets us opt-in, which was can't currently do in Chef-12.
Diffstat (limited to 'lib/chef/property.rb')
-rw-r--r-- | lib/chef/property.rb | 11 |
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 |