summaryrefslogtreecommitdiff
path: root/lib/chef
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-06-03 16:27:16 -0700
committerJohn Keiser <john@johnkeiser.com>2015-06-23 15:23:02 -0700
commitd91ed1d763aa35b29d22d712077bc965ce7098b2 (patch)
treeafc3b9be0f61fcc25c962a91481cf2e37c54937e /lib/chef
parenta2ddd1133c57f7ae25cdebd0eb860bb8c3b148ad (diff)
downloadchef-d91ed1d763aa35b29d22d712077bc965ce7098b2.tar.gz
Make "is" fail if you pass nil and don't validate it
Diffstat (limited to 'lib/chef')
-rw-r--r--lib/chef/mixin/params_validate.rb19
1 files changed, 8 insertions, 11 deletions
diff --git a/lib/chef/mixin/params_validate.rb b/lib/chef/mixin/params_validate.rb
index 629243412d..db25ecd847 100644
--- a/lib/chef/mixin/params_validate.rb
+++ b/lib/chef/mixin/params_validate.rb
@@ -245,19 +245,16 @@ class Chef
# Compare the way "case" would (i.e. `===`)
def _pv_is(opts, key, to_be)
value = _pv_opts_lookup(opts, key)
- unless value.nil?
- passes = false
- to_be = Array(to_be)
- to_be.each do |tb|
- if tb.is_a?(Proc)
- return if instance_exec(value, &tb)
- else
- return if tb === value
- end
+ to_be = [ to_be ].flatten(1)
+ to_be.each do |tb|
+ if tb.is_a?(Proc)
+ return if instance_exec(value, &tb)
+ else
+ return if tb === value
end
-
- raise Exceptions::ValidationFailed, "Option #{key} must be one of: #{to_be.join(", ")}! You passed #{value.inspect}."
end
+
+ raise Exceptions::ValidationFailed, "Option #{key} must be one of: #{to_be.join(", ")}! You passed #{value.inspect}."
end
end
end