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, raise_if_missing_params, #to_json, #to_s, #valid?

Constructor Details

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

Returns a new instance of ArrayValidator.



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

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



227
228
229
230
231
# File 'lib/apipie/validator.rb', line 227

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



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

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

#expected_typeObject



223
224
225
# File 'lib/apipie/validator.rb', line 223

def expected_type
  "array"
end

#process_value(values) ⇒ Object



215
216
217
# File 'lib/apipie/validator.rb', line 215

def process_value(values)
  values || []
end

#validate(values) ⇒ Object



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

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