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