Class: Apipie::Validator::TypeValidator
Overview
Instance Attribute Summary
#param_description
Class Method Summary
collapse
Instance Method Summary
collapse
#==, #error, find, #format_description_value, #ignore_allow_blank?, inherited, #inspect, #inspected_fields, #merge_with, #param_name, #params_ordered, #to_json, #to_s, #valid?
Constructor Details
#initialize(param_description, argument) ⇒ TypeValidator
Returns a new instance of TypeValidator.
109
110
111
112
|
# File 'lib/apipie/validator.rb', line 109
def initialize(param_description, argument)
super(param_description)
@type = argument
end
|
Class Method Details
.build(param_description, argument, options, block) ⇒ Object
119
120
121
122
123
|
# File 'lib/apipie/validator.rb', line 119
def self.build(param_description, argument, options, block)
if argument.is_a?(Class) && (argument != Hash || block.nil?)
self.new(param_description, argument)
end
end
|
Instance Method Details
#description ⇒ Object
125
126
127
|
# File 'lib/apipie/validator.rb', line 125
def description
"Must be a #{@type}"
end
|
#expected_type ⇒ Object
129
130
131
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/apipie/validator.rb', line 129
def expected_type
if @type.ancestors.include? Hash
'hash'
elsif @type.ancestors.include? Array
'array'
elsif @type.ancestors.include? Numeric
'numeric'
elsif @type.ancestors.include? File
'file'
else
'string'
end
end
|
#validate(value) ⇒ Object
114
115
116
117
|
# File 'lib/apipie/validator.rb', line 114
def validate(value)
return false if value.nil?
value.is_a? @type
end
|