mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
use restriction instead of check
This commit is contained in:
parent
fdc3086976
commit
41c895c0d9
@ -4,7 +4,7 @@ module ValidatesTimeliness
|
|||||||
class Validator < ActiveModel::EachValidator
|
class Validator < ActiveModel::EachValidator
|
||||||
include Conversion
|
include Conversion
|
||||||
|
|
||||||
CHECKS = {
|
RESTRICTIONS = {
|
||||||
:is_at => :==,
|
:is_at => :==,
|
||||||
:before => :<,
|
:before => :<,
|
||||||
:after => :>,
|
:after => :>,
|
||||||
@ -38,10 +38,10 @@ module ValidatesTimeliness
|
|||||||
|
|
||||||
value = type_cast(value)
|
value = type_cast(value)
|
||||||
|
|
||||||
(CHECKS.keys & options.keys).each do |check|
|
(RESTRICTIONS.keys & options.keys).each do |restriction|
|
||||||
check_value = type_cast(options[check])
|
restriction_value = type_cast(evaluate_option_value(options[restriction], record))
|
||||||
unless value.send(CHECKS[check], check_value)
|
unless value.send(RESTRICTIONS[restriction], restriction_value)
|
||||||
return record.errors.add(attr_name, check, :restriction => check_value)
|
return record.errors.add(attr_name, restriction, :restriction => restriction_value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user