Class: Apipie::Validator::ArrayValidator

Inherits:
BaseValidator show all
Defined in:
lib/apipie/validator.rb

Overview

arguments value must be an array

Instance Attribute Summary

Attributes inherited from BaseValidator

#param_description

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseValidator

#error, find, inherited, #merge_with, #param_name, #params_ordered, #to_json, #to_s, #valid?

Constructor Details

#initialize(param_description, argument, options = {}) ⇒ ArrayValidator

Returns a new instance of ArrayValidator.



158
159
160
161
162
163
# File 'lib/apipie/validator.rb', line 158

def initialize(param_description, argument, options={})
  super(param_description)
  @type = argument
  @items_type = options[:of]
  @items_enum = options[:in]
end

Class Method Details

.build(param_description, argument, options, block) ⇒ Object



182
183
184
185
186
# File 'lib/apipie/validator.rb', line 182

def self.build(param_description, argument, options, block)
  if argument == Array && !block.is_a?(Proc)
    self.new(param_description, argument, options)
  end
end

Instance Method Details

#descriptionObject



174
175
176
# File 'lib/apipie/validator.rb', line 174

def description
  "Must be an array of #{items}"
end

#expected_typeObject



178
179
180
# File 'lib/apipie/validator.rb', line 178

def expected_type
  "array"
end

#process_value(values) ⇒ Object



170
171
172
# File 'lib/apipie/validator.rb', line 170

def process_value(values)
  values || []
end

#validate(values) ⇒ Object



165
166
167
168
# File 'lib/apipie/validator.rb', line 165

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