24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/input_sanitizer/v2/types.rb', line 24
def call(value, options = {})
if value == nil || value == 'null'
if options[:allow_nil] == false || options[:allow_blank] == false || options[:required] == true
raise InputSanitizer::BlankValueError
else
nil
end
else
Integer(value).tap do |integer|
raise InputSanitizer::ValueError.new(value, options[:minimum], options[:maximum]) if options[:minimum] && integer < options[:minimum]
raise InputSanitizer::ValueError.new(value, options[:minimum], options[:maximum]) if options[:maximum] && integer > options[:maximum]
end
end
rescue ArgumentError
raise InputSanitizer::TypeMismatchError.new(value, :integer)
end
|