Class: ParamsChecker::ParamChecker::NumParamChecker
Instance Attribute Summary
#key, #params, #schema
Instance Method Summary
collapse
#add_field_error, #initialize
Instance Method Details
#call ⇒ Object
24
25
26
27
28
29
|
# File 'lib/params_checker/param_checker.rb', line 24
def call
return nil if schema[key][:allow_nil] && params[key].nil?
check_type && check_param
params[key]
end
|
#check_param ⇒ Object
37
38
39
40
41
42
43
|
# File 'lib/params_checker/param_checker.rb', line 37
def check_param
min = schema[key][:min]
max = schema[key][:max]
valid = (min..max).include? params[key]
add_field_error("This numeric field's value must be in range from #{min} to #{max}.") unless valid
valid
end
|
#check_type ⇒ Object
31
32
33
34
35
|
# File 'lib/params_checker/param_checker.rb', line 31
def check_type
valid = params[key].is_a? Numeric
add_field_error("This field's type must be numeric.") unless valid
valid
end
|