Class: Apipie::Validator::EnumValidator

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

Overview

arguments value must be one of given in array

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) ⇒ EnumValidator

Returns a new instance of EnumValidator.



178
179
180
181
# File 'lib/apipie/validator.rb', line 178

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

Class Method Details

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



187
188
189
# File 'lib/apipie/validator.rb', line 187

def self.build(param_description, argument, options, proc)
  self.new(param_description, argument) if argument.is_a?(Array)
end

Instance Method Details

#descriptionObject



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

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

#validate(value) ⇒ Object



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

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

#valuesObject



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

def values
  @array
end