Class: Apipie::Validator::ArrayClassValidator

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

Instance Attribute Summary

Attributes inherited from BaseValidator

#param_description

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseValidator

#==, #error, #expected_type, 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) ⇒ ArrayClassValidator

Returns a new instance of ArrayClassValidator.



280
281
282
283
# File 'lib/apipie/validator.rb', line 280

def initialize(param_description, argument)
  super(param_description)
  @array = argument
end

Class Method Details

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



289
290
291
292
293
# File 'lib/apipie/validator.rb', line 289

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

Instance Method Details

#descriptionObject



295
296
297
298
# File 'lib/apipie/validator.rb', line 295

def description
  string = @array.map { |value| format_description_value(value) }.join(', ')
  "Must be one of: #{string}."
end

#validate(value) ⇒ Object



285
286
287
# File 'lib/apipie/validator.rb', line 285

def validate(value)
  @array.include?(value.class)
end