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



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

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



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

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



198
199
200
# File 'lib/apipie/validator.rb', line 198

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

#expected_typeObject



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

def expected_type
  "array"
end

#process_value(values) ⇒ Object



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

def process_value(values)
  values || []
end

#validate(values) ⇒ Object



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

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