summaryrefslogtreecommitdiff
path: root/lib/chef/cookbook/metadata.rb
diff options
context:
space:
mode:
authorSteve Rude <srude@riotgames.com>2014-02-03 13:38:14 -0800
committerSteve Rude <srude@riotgames.com>2014-02-03 13:38:14 -0800
commitee236d095f8d2e2a0d3cb0e158066fd2b654a54d (patch)
treead63e44051a7b7e00302de27ff1e38163634f046 /lib/chef/cookbook/metadata.rb
parent4312ebe6e4d651f248d215519acecf93a19e2d8a (diff)
downloadchef-ee236d095f8d2e2a0d3cb0e158066fd2b654a54d.tar.gz
Update to allow boolean and numeric attributes
Diffstat (limited to 'lib/chef/cookbook/metadata.rb')
-rw-r--r--lib/chef/cookbook/metadata.rb19
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/chef/cookbook/metadata.rb b/lib/chef/cookbook/metadata.rb
index b9b32c8224..ad0f4afc41 100644
--- a/lib/chef/cookbook/metadata.rb
+++ b/lib/chef/cookbook/metadata.rb
@@ -391,14 +391,14 @@ class Chef
:description => { :kind_of => String },
:choice => { :kind_of => [ Array ], :default => [] },
:calculated => { :equal_to => [ true, false ], :default => false },
- :type => { :equal_to => [ "string", "array", "hash", "symbol" ], :default => "string" },
+ :type => { :equal_to => [ "string", "array", "hash", "symbol", "boolean", "numeric" ], :default => "string" },
:required => { :equal_to => [ "required", "recommended", "optional", true, false ], :default => "optional" },
:recipes => { :kind_of => [ Array ], :default => [] },
- :default => { :kind_of => [ String, Array, Hash ] }
+ :default => { :kind_of => [ String, Array, Hash, Symbol, Numeric, TrueClass, FalseClass ] }
}
)
options[:required] = remap_required_attribute(options[:required]) unless options[:required].nil?
- validate_string_array(options[:choice])
+ validate_choice_array(options)
validate_calculated_default_rule(options)
validate_choice_default_rule(options)
@@ -546,6 +546,19 @@ INVALID
end
end
+ # Validate the choice of the options hash
+ #
+ # Raise an exception if the members of the array do not match the defaults
+ # === Parameters
+ # opts<Hash>:: The options hash
+ def validate_choice_array(opts)
+ if opts[:choices].kind_of?(Array)
+ opts[:choices].each do |choice|
+ validate( {:choice => choice}, {:choice => opts[:default]} )
+ end
+ end
+ end
+
# For backwards compatibility, remap Boolean values to String
# true is mapped to "required"
# false is mapped to "optional"