diff options
author | John Keiser <john@johnkeiser.com> | 2015-06-30 14:12:29 -0600 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2015-07-03 13:10:23 -0600 |
commit | 901f122c5a906b8f64e8ed1919674ffe9d839bf0 (patch) | |
tree | d0003f285b5058440e1c6216612b15256aaff6d9 /lib/chef/mixin/params_validate.rb | |
parent | 88e90f48952d0776b2d2b5f641c3d1b08c1376bb (diff) | |
download | chef-901f122c5a906b8f64e8ed1919674ffe9d839bf0.tar.gz |
Bring set_or_return behavior back in line with what it used to be
Diffstat (limited to 'lib/chef/mixin/params_validate.rb')
-rw-r--r-- | lib/chef/mixin/params_validate.rb | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/lib/chef/mixin/params_validate.rb b/lib/chef/mixin/params_validate.rb index 1f335f6722..322caea474 100644 --- a/lib/chef/mixin/params_validate.rb +++ b/lib/chef/mixin/params_validate.rb @@ -119,7 +119,7 @@ class Chef end def set_or_return(symbol, value, validation) - property = Property::NonDeprecatedNilGetter.new(name: symbol, **validation) + property = SetOrReturnProperty.new(name: symbol, **validation) property.call(self, value) end @@ -441,6 +441,29 @@ class Chef opts[key.to_sym] = instance_exec(opts[key], &coercer) end end + + # Used by #set_or_return to avoid emitting a deprecation warning for + # "value nil" and to keep default stickiness working exactly the same + # @api private + class SetOrReturnProperty < Chef::Property + def get(resource) + value = super + # All values are sticky, frozen or not + if !is_set?(resource) + set_value(resource, value) + end + value + end + + def call(resource, value=NOT_PASSED) + # setting to nil does a get + if value.nil? && !explicitly_accepts_nil?(resource) + get(resource) + else + super + end + end + end end end end |