diff options
| author | Randy Morgan <[email protected]> | 2013-01-10 18:27:27 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2013-01-10 18:27:27 +0900 |
| commit | 58e8dd8a2b1a4a85ac77bf680914daf16eb695f1 (patch) | |
| tree | 980bf825b4b5c5fb55ef55b1b7f0ea2eb9b13533 /lib/axlsx/util/validators.rb | |
| parent | f7eeb07abfa1c58552847b2b38787f44cd3e2d24 (diff) | |
| download | caxlsx-58e8dd8a2b1a4a85ac77bf680914daf16eb695f1.tar.gz caxlsx-58e8dd8a2b1a4a85ac77bf680914daf16eb695f1.zip | |
reduced processing of 3000 rows from 3+ seconds to just under 2
Diffstat (limited to 'lib/axlsx/util/validators.rb')
| -rw-r--r-- | lib/axlsx/util/validators.rb | 13 |
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 |
