summaryrefslogtreecommitdiff
path: root/lib/chef/property.rb
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-09-22 22:39:41 -0700
committerJohn Keiser <john@johnkeiser.com>2015-09-22 22:50:28 -0700
commit71fc5c5650f8bd3ec819087d6a5ca7f4eaeb1158 (patch)
tree226bda12feeb960b147177a5150d1efee731bbc0 /lib/chef/property.rb
parentd8f7ca4d08f00db96fbf1e98a7f1ed763c7bab01 (diff)
downloadchef-71fc5c5650f8bd3ec819087d6a5ca7f4eaeb1158.tar.gz
Add deprecation warning for properties that specify default and name_propertyjk/default-ignoring
Diffstat (limited to 'lib/chef/property.rb')
-rw-r--r--lib/chef/property.rb16
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/chef/property.rb b/lib/chef/property.rb
index 5b6a969d5f..7f42616bdd 100644
--- a/lib/chef/property.rb
+++ b/lib/chef/property.rb
@@ -86,22 +86,24 @@ class Chef
#
def initialize(**options)
options.each { |k,v| options[k.to_sym] = v if k.is_a?(String) }
+
# Only pick the first of :default, :name_property and :name_attribute if
# more than one is specified.
- found_default = false
+ found_defaults = []
options.reject! do |k,v|
if [ :name_property, :name_attribute, :default ].include?(k)
- if found_default
- true
- else
- found_default = true
- false
- end
+ found_defaults << k
+ # Reject all but the first default key you find
+ found_defaults.size > 1
else
false
end
end
+ if found_defaults.size > 1
+ Chef::Log.deprecation("Cannot specify keys #{found_defaults.join(", ")} together on property #{options[:name]}--only the first one (#{found_defaults[0]}) will be obeyed. Please pick one.", caller(5..5)[0])
+ end
options[:name_property] = options.delete(:name_attribute) if options.has_key?(:name_attribute) && !options.has_key?(:name_property)
+
@options = options
options[:name] = options[:name].to_sym if options[:name]