use implied_type in restriction evaluations

This commit is contained in:
Adam Meehan 2009-09-12 12:26:02 +10:00
parent 899e96b880
commit d3c5101f92

View File

@ -54,23 +54,20 @@ module ValidatesTimeliness
end end
def validate_restrictions(record, attr_name, value) def validate_restrictions(record, attr_name, value)
restriction_type = type
if configuration[:with_time] || configuration[:with_date] if configuration[:with_time] || configuration[:with_date]
restriction_type = :datetime
value = combine_date_and_time(value, record) value = combine_date_and_time(value, record)
end end
value = self.class.type_cast_value(value, restriction_type, configuration[:ignore_usec]) value = self.class.type_cast_value(value, implied_type, configuration[:ignore_usec])
return if value.nil? return if value.nil?
RESTRICTION_METHODS.each do |option, method| RESTRICTION_METHODS.each do |option, method|
next unless restriction = configuration[option] next unless restriction = configuration[option]
begin begin
restriction = self.class.evaluate_option_value(restriction, restriction_type, record) restriction = self.class.evaluate_option_value(restriction, implied_type, record)
next if restriction.nil? next if restriction.nil?
restriction = self.class.type_cast_value(restriction, restriction_type, configuration[:ignore_usec]) restriction = self.class.type_cast_value(restriction, implied_type, configuration[:ignore_usec])
unless evaluate_restriction(restriction, value, method) unless evaluate_restriction(restriction, value, method)
add_error(record, attr_name, option, interpolation_values(option, restriction)) add_error(record, attr_name, option, interpolation_values(option, restriction))
@ -149,6 +146,10 @@ module ValidatesTimeliness
options.assert_valid_keys(VALID_OPTIONS - invalid_for_type) options.assert_valid_keys(VALID_OPTIONS - invalid_for_type)
end end
def implied_type
@implied_type ||= configuration[:with_date] || configuration[:with_time] ? :datetime : type
end
# class methods # class methods
class << self class << self