summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/util/validators.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/axlsx/util/validators.rb')
-rw-r--r--lib/axlsx/util/validators.rb13
1 files changed, 7 insertions, 6 deletions
diff --git a/lib/axlsx/util/validators.rb b/lib/axlsx/util/validators.rb
index aa8eb1ac..739a4de2 100644
--- a/lib/axlsx/util/validators.rb
+++ b/lib/axlsx/util/validators.rb
@@ -51,17 +51,18 @@ module Axlsx
# @raise [ArugumentError] Raised if the class of the value provided is not in the specified array of types or the block passed returns false
# @return [Boolean] true if validation succeeds.
# @see validate_boolean
- def self.validate(name, types, v, other= lambda{|arg| true })
+ def self.validate(name, types, v, other=false)
types = [types] unless types.is_a? Array
- valid_type = false
+ if other.is_a?(Proc)
+ raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect]) unless other.call(v)
+ end
if v.class == Class
- types.each { |t| valid_type = true if v.ancestors.include?(t) }
+ types.each { |t| return if v.ancestors.include?(t) }
else
- types.each { |t| valid_type = true if v.is_a?(t) }
+ types.each { |t| return if v.is_a?(t) }
end
- raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect]) unless (other.call(v) && valid_type)
+ raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect])
end
- true
end