Class: Axlsx::DataTypeValidator
- Inherits:
-
Object
- Object
- Axlsx::DataTypeValidator
- Defined in:
- lib/axlsx/util/validators.rb
Overview
Validate that the class of the value provided is either an instance or the class of the allowed types and that any specified additional validation returns true.
Class Method Summary collapse
-
.validate(name, types, v, other = lambda{|arg| true }) ⇒ Boolean
Perform validation.
Class Method Details
.validate(name, types, v, other = lambda{|arg| true }) ⇒ Boolean
Perform validation
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/axlsx/util/validators.rb', line 35 def self.validate(name, types, v, other= lambda{|arg| true }) types = [types] unless types.is_a? Array valid_type = false if v.class == Class types.each { |t| valid_type = true if v.ancestors.include?(t) } else types.each { |t| valid_type = true if v.is_a?(t) } end raise ArgumentError, (ERR_TYPE % [v.inspect, name, types.inspect]) unless (other.call(v) && valid_type) end |