class ApipieDSL::Validator::ArrayValidator
Public Class Methods
build(param_description, argument, options, block)
click to toggle source
# File lib/apipie_dsl/validator.rb, line 193 def self.build(param_description, argument, options, block) return if argument != Array || block.is_a?(Proc) new(param_description, argument, options) end
new(param_description, argument, options = {})
click to toggle source
Calls superclass method
ApipieDSL::Validator::BaseValidator::new
# File lib/apipie_dsl/validator.rb, line 186 def initialize(param_description, argument, options = {}) super(param_description) @type = argument @items_type = options[:of] @items_enum = options[:in] end
Public Instance Methods
description()
click to toggle source
# File lib/apipie_dsl/validator.rb, line 210 def description "Must be an array of #{items_type}" end
expected_type()
click to toggle source
# File lib/apipie_dsl/validator.rb, line 214 def expected_type 'array' end
process_value(values)
click to toggle source
# File lib/apipie_dsl/validator.rb, line 206 def process_value(values) values || [] end
validate(values)
click to toggle source
# File lib/apipie_dsl/validator.rb, line 199 def validate(values) return false unless process_value(values).respond_to?(:each) && !process_value(values).is_a?(String) process_value(values).all? { |v| validate_item(v) } end
Private Instance Methods
items_enum()
click to toggle source
# File lib/apipie_dsl/validator.rb, line 236 def items_enum @items_enum = Array(@items_enum.call) if @items_enum.is_a?(Proc) @items_enum end
items_type()
click to toggle source
# File lib/apipie_dsl/validator.rb, line 249 def items_type return items_enum.inspect if items_enum @items_type || 'any type' end
valid_type?(value)
click to toggle source
# File lib/apipie_dsl/validator.rb, line 224 def valid_type?(value) return true unless @items_type item_validator = BaseValidator.find(nil, @items_type, nil, nil) if item_validator item_validator.valid?(value) else value.is_a?(@items_type) end end
valid_value?(value)
click to toggle source
# File lib/apipie_dsl/validator.rb, line 241 def valid_value?(value) if items_enum items_enum.include?(value) else true end end
validate_item(value)
click to toggle source
# File lib/apipie_dsl/validator.rb, line 220 def validate_item(value) valid_type?(value) && valid_value?(value) end