Class: Apipie::Validator::EnumValidator
Overview
arguments value must be one of given in array
Instance Attribute Summary
#param_description
Class Method Summary
collapse
Instance Method Summary
collapse
#==, #error, #expected_type, find, #format_description_value, #ignore_allow_blank?, 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.
168
169
170
171
|
# File 'lib/apipie/validator.rb', line 168
def initialize(param_description, argument)
super(param_description)
@array = argument
end
|
Class Method Details
.build(param_description, argument, options, proc) ⇒ Object
177
178
179
|
# File 'lib/apipie/validator.rb', line 177
def self.build(param_description, argument, options, proc)
self.new(param_description, argument) if argument.is_a?(Array)
end
|
Instance Method Details
#description ⇒ Object
185
186
187
188
|
# File 'lib/apipie/validator.rb', line 185
def description
string = @array.map { |value| format_description_value(value) }.join(', ')
"Must be one of: #{string}."
end
|
#validate(value) ⇒ Object
173
174
175
|
# File 'lib/apipie/validator.rb', line 173
def validate(value)
@array.include?(value)
end
|
#values ⇒ Object
181
182
183
|
# File 'lib/apipie/validator.rb', line 181
def values
@array
end
|