Class: Restapi::Validator::TypeValidator
Overview
Instance Attribute Summary
#param_name
Class Method Summary
collapse
Instance Method Summary
collapse
find, #to_json, #to_s, #valid?
Constructor Details
Returns a new instance of TypeValidator.
49
50
51
52
|
# File 'lib/restapi/validator.rb', line 49
def initialize(argument)
@type = argument
@type = Integer if @type == Fixnum
end
|
Class Method Details
.build(argument, options, block) ⇒ Object
63
64
65
|
# File 'lib/restapi/validator.rb', line 63
def self.build(argument, options, block)
self.new(argument) if argument.is_a?(Class) && argument != Hash
end
|
Instance Method Details
#description ⇒ Object
71
72
73
|
# File 'lib/restapi/validator.rb', line 71
def description
"Parameter has to be #{@type}."
end
|
#error ⇒ Object
67
68
69
|
# File 'lib/restapi/validator.rb', line 67
def error
"Parameter #{@param_name} expecting to be #{@type.name}, got: #{@error_value.class.name}"
end
|
#validate(value) ⇒ Object
54
55
56
57
58
59
60
61
|
# File 'lib/restapi/validator.rb', line 54
def validate(value)
return false if value.nil?
begin
Kernel.send(@type.to_s, value)
rescue ArgumentError
return false
end
end
|