Class: ParamsChecker::ParamChecker::IntParamChecker
Instance Attribute Summary
#fields, #key, #opts
Instance Method Summary
collapse
#add_error, #initialize
Instance Method Details
#call ⇒ Object
47
48
49
50
51
52
|
# File 'lib/params_checker/param_checker.rb', line 47
def call
return nil if fields[key][:allow_nil] && opts[key].nil?
check_type && check_param
opts[key]
end
|
#check_param ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/params_checker/param_checker.rb', line 60
def check_param
min = fields[key][:min]
max = fields[key][:max]
valid = (min..max).include? opts[key]
add_error("This integer field's value must be in range from #{min} to #{max}.") unless valid
valid
end
|
#check_type ⇒ Object
54
55
56
57
58
|
# File 'lib/params_checker/param_checker.rb', line 54
def check_type
valid = opts[key].is_a? Integer
add_error("This field's type must be integer.") unless valid
valid
end
|