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, #format_description_value, inherited, #inspect, #inspected_fields, #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.



188
189
190
191
192
193
# File 'lib/apipie/validator.rb', line 188

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



212
213
214
215
216
# File 'lib/apipie/validator.rb', line 212

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



204
205
206
# File 'lib/apipie/validator.rb', line 204

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

#expected_typeObject



208
209
210
# File 'lib/apipie/validator.rb', line 208

def expected_type
  "array"
end

#process_value(values) ⇒ Object



200
201
202
# File 'lib/apipie/validator.rb', line 200

def process_value(values)
  values || []
end

#validate(values) ⇒ Object



195
196
197
198
# File 'lib/apipie/validator.rb', line 195

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