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.
133
134
135
136
|
# File 'lib/restapi/validator.rb', line 133
def initialize(param_description, argument)
super(param_description)
@array = argument
end
|
Class Method Details
.build(param_description, argument, options, proc) ⇒ Object
142
143
144
|
# File 'lib/restapi/validator.rb', line 142
def self.build(param_description, argument, options, proc)
self.new(param_description, argument) if argument.is_a?(Array)
end
|
Instance Method Details
#description ⇒ Object
150
151
152
|
# File 'lib/restapi/validator.rb', line 150
def description
"Parameter has to be one of: #{@array.join(', ')}."
end
|
#error ⇒ Object
146
147
148
|
# File 'lib/restapi/validator.rb', line 146
def error
"Parameter #{param_name} has bad value (#{@error_value.inspect}). Expecting one of: #{@array.join(',')}."
end
|
#validate(value) ⇒ Object
138
139
140
|
# File 'lib/restapi/validator.rb', line 138
def validate(value)
@array.include?(value)
end
|