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

Constructor Details

#initialize(param_description, argument) ⇒ EnumValidator

Returns a new instance of EnumValidator.



138
139
140
141
# File 'lib/apipie/validator.rb', line 138

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

Class Method Details

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



147
148
149
# File 'lib/apipie/validator.rb', line 147

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

Instance Method Details

#descriptionObject



151
152
153
# File 'lib/apipie/validator.rb', line 151

def description
  "Must be one of: #{@array.join(', ')}."
end

#validate(value) ⇒ Object



143
144
145
# File 'lib/apipie/validator.rb', line 143

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