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, inherited, #inspect, #inspected_fields, #merge_with, #param_name, #params_ordered, #to_json, #to_s, #valid?

Constructor Details

#initialize(param_description, argument) ⇒ EnumValidator

Returns a new instance of EnumValidator.



157
158
159
160
# File 'lib/apipie/validator.rb', line 157

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

Class Method Details

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



166
167
168
# File 'lib/apipie/validator.rb', line 166

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

Instance Method Details

#descriptionObject



174
175
176
177
# File 'lib/apipie/validator.rb', line 174

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

#validate(value) ⇒ Object



162
163
164
# File 'lib/apipie/validator.rb', line 162

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

#valuesObject



170
171
172
# File 'lib/apipie/validator.rb', line 170

def values
  @array
end