FEATURE: allow for a localized error when a regex fails in site settings

FEATURE: apply string validation to list site settings (so we get regex)
This commit is contained in:
Sam
2015-02-27 11:45:56 +11:00
parent ea40dd08e6
commit 0742f340f9
7 changed files with 26 additions and 4 deletions

View File

@ -2,6 +2,7 @@ class StringSettingValidator
def initialize(opts={})
@opts = opts
@regex = Regexp.new(opts[:regex]) if opts[:regex]
@regex_error = opts[:regex_error] || 'site_settings.errors.regex_mismatch'
end
def valid_value?(val)
@ -22,7 +23,7 @@ class StringSettingValidator
def error_message
if @regex_fail
I18n.t('site_settings.errors.regex_mismatch')
I18n.t(@regex_error)
elsif @length_fail
if @opts[:min] && @opts[:max]
I18n.t('site_settings.errors.invalid_string_min_max', {min: @opts[:min], max: @opts[:max]})