Class: Apipie::Validator::ArrayValidator

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

Constructor Details

#initialize(param_description, argument) ⇒ ArrayValidator

Returns a new instance of ArrayValidator.



135
136
137
138
# File 'lib/apipie/validator.rb', line 135

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

Class Method Details

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



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

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

Instance Method Details

#descriptionObject



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

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

#validate(value) ⇒ Object



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

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