2014-06-12 17:03:03 -05:00
|
|
|
class IntegerSettingValidator
|
|
|
|
def initialize(opts={})
|
|
|
|
@opts = opts
|
2017-04-20 02:49:50 -05:00
|
|
|
@opts[:min] = 0 unless @opts[:min].present?
|
|
|
|
@opts[:max] = 20000 unless @opts[:max].present?
|
2014-06-12 17:03:03 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def valid_value?(val)
|
|
|
|
return false if val.to_i.to_s != val.to_s
|
|
|
|
return false if @opts[:min] and @opts[:min].to_i > val.to_i
|
|
|
|
return false if @opts[:max] and @opts[:max].to_i < val.to_i
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2014-06-18 09:49:21 -05:00
|
|
|
def error_message
|
2014-06-12 17:03:03 -05:00
|
|
|
if @opts[:min] && @opts[:max]
|
|
|
|
I18n.t('site_settings.errors.invalid_integer_min_max', {min: @opts[:min], max: @opts[:max]})
|
|
|
|
elsif @opts[:min]
|
|
|
|
I18n.t('site_settings.errors.invalid_integer_min', {min: @opts[:min]})
|
|
|
|
elsif @opts[:max]
|
|
|
|
I18n.t('site_settings.errors.invalid_integer_max', {max: @opts[:max]})
|
|
|
|
else
|
|
|
|
I18n.t('site_settings.errors.invalid_integer')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|