Add method ApplicationEachValidator::Validation#str_value
This commit is contained in:
parent
7fb4404432
commit
63e1ba6e58
|
@ -35,5 +35,9 @@ class ApplicationEachValidator < ActiveModel::EachValidator
|
|||
error(*args)
|
||||
throw :stop_validating
|
||||
end
|
||||
|
||||
def str_value
|
||||
@str_value ||= String(value).dup.freeze
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,10 +8,10 @@ class CodenameValidator < ApplicationEachValidator
|
|||
MAX = 36
|
||||
|
||||
def perform
|
||||
error! :blank if value.to_s.blank?
|
||||
error! :blank if str_value.blank?
|
||||
error! :codename unless CODENAME_RE.match? value
|
||||
error! :too_short, count: MIN if value.to_s.length < MIN
|
||||
error! :too_long, count: MAX if value.to_s.length > MAX
|
||||
error! :too_short, count: MIN if str_value.length < MIN
|
||||
error! :too_long, count: MAX if str_value.length > MAX
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,8 +7,8 @@ class GoodBigTextValidator < GoodTextValidator
|
|||
|
||||
def perform
|
||||
super
|
||||
error :too_short, count: MIN if value.to_s.length < MIN
|
||||
error :too_long, count: MAX if value.to_s.length > MAX
|
||||
error :too_short, count: MIN if str_value.length < MIN
|
||||
error :too_long, count: MAX if str_value.length > MAX
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,8 +7,8 @@ class GoodSmallTextValidator < GoodTextValidator
|
|||
|
||||
def perform
|
||||
super
|
||||
error :too_short, count: MIN if value.to_s.length < MIN
|
||||
error :too_long, count: MAX if value.to_s.length > MAX
|
||||
error :too_short, count: MIN if str_value.length < MIN
|
||||
error :too_long, count: MAX if str_value.length > MAX
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ class GoodTextValidator < ApplicationEachValidator
|
|||
GOOD_TEXT_RE = /\A[^\s](.*[^\s])?\z/.freeze
|
||||
|
||||
def perform
|
||||
error :blank if value.to_s.blank?
|
||||
error :blank if str_value.blank?
|
||||
error :good_text unless GOOD_TEXT_RE.match? value
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ class TimezoneValidator < ApplicationEachValidator
|
|||
TIMEZONE_RE = /\A-?\d\d:\d\d:00\z/.freeze
|
||||
|
||||
def perform
|
||||
error! :blank if value.to_s.blank?
|
||||
error! :blank if str_value.blank?
|
||||
error! :timezone unless TIMEZONE_RE.match? value
|
||||
end
|
||||
end
|
||||
|
|
Reference in New Issue