Class: Restapi::Validator::ArrayValidator
Overview
arguments value must be one of given in array
Instance Attribute Summary
#param_description
Class Method Summary
collapse
Instance Method Summary
collapse
#expected_type, find, inherited, #param_name, #to_json, #to_s, #valid?
Constructor Details
#initialize(param_description, argument) ⇒ ArrayValidator
Returns a new instance of ArrayValidator.
132
133
134
135
|
# File 'lib/restapi/validator.rb', line 132
def initialize(param_description, argument)
super(param_description)
@array = argument
end
|
Class Method Details
.build(param_description, argument, options, proc) ⇒ Object
141
142
143
|
# File 'lib/restapi/validator.rb', line 141
def self.build(param_description, argument, options, proc)
self.new(param_description, argument) if argument.is_a?(Array)
end
|
Instance Method Details
#description ⇒ Object
149
150
151
|
# File 'lib/restapi/validator.rb', line 149
def description
"Parameter has to be one of: #{@array.join(', ')}."
end
|
#error ⇒ Object
145
146
147
|
# File 'lib/restapi/validator.rb', line 145
def error
"Parameter #{param_name} has bad value (#{@error_value.inspect}). Expecting one of: #{@array.join(',')}."
end
|
#validate(value) ⇒ Object
137
138
139
|
# File 'lib/restapi/validator.rb', line 137
def validate(value)
@array.include?(value)
end
|