use restriction instead of check

This commit is contained in:
Adam Meehan 2010-08-01 20:53:41 +10:00
parent fdc3086976
commit 41c895c0d9

View File

@ -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