Class: Restapi::Validator::ProcValidator
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) ⇒ ProcValidator
Returns a new instance of ProcValidator.
156
157
158
159
|
# File 'lib/restapi/validator.rb', line 156
def initialize(param_description, argument)
super(param_description)
@proc = argument
end
|
Class Method Details
.build(param_description, argument, options, proc) ⇒ Object
165
166
167
|
# File 'lib/restapi/validator.rb', line 165
def self.build(param_description, argument, options, proc)
self.new(param_description, argument) if argument.is_a?(Proc) && argument.arity == 1
end
|
Instance Method Details
#description ⇒ Object
173
174
175
|
# File 'lib/restapi/validator.rb', line 173
def description
""
end
|
#error ⇒ Object
169
170
171
|
# File 'lib/restapi/validator.rb', line 169
def error
"Parameter #{param_name} has bad value (\"#{@error_value}\"). #{@help}"
end
|
#validate(value) ⇒ Object
161
162
163
|
# File 'lib/restapi/validator.rb', line 161
def validate(value)
(@help = @proc.call(value)) === true
end
|