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.
157
158
159
160
|
# File 'lib/restapi/validator.rb', line 157
def initialize(param_description, argument)
super(param_description)
@proc = argument
end
|
Class Method Details
.build(param_description, argument, options, proc) ⇒ Object
166
167
168
|
# File 'lib/restapi/validator.rb', line 166
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
174
175
176
|
# File 'lib/restapi/validator.rb', line 174
def description
""
end
|
#error ⇒ Object
170
171
172
|
# File 'lib/restapi/validator.rb', line 170
def error
"Parameter #{param_name} has bad value (\"#{@error_value}\"). #{@help}"
end
|
#validate(value) ⇒ Object
162
163
164
|
# File 'lib/restapi/validator.rb', line 162
def validate(value)
(@help = @proc.call(value)) === true
end
|