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, #ignore_allow_blank?, 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.



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

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



217
218
219
220
221
# File 'lib/apipie/validator.rb', line 217

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



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

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

#expected_typeObject



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

def expected_type
  "array"
end

#process_value(values) ⇒ Object



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

def process_value(values)
  values || []
end

#validate(values) ⇒ Object



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

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