def validate_attribute record, attribute_name, raw
each_value(raw) do |raw_value|
if options[:only_integer] or options[:odd] or options[:even]
value = as_integer(raw_value)
error_type = :not_an_integer
else
value = as_number(raw_value)
error_type = :not_a_number
end
unless value
record.errors.add(attribute_name, message_for(error_type))
return
end
COMPARISONS.each do |option,method|
next unless options.has_key?(option)
requirement = case options[option]
when Symbol then record.send(options[option])
when Proc then options[option].call(record)
else options[option]
end
valid = case method
when Symbol then value.send(method, requirement)
else method.call(value)
end
unless valid
message = message_for(option, requirement)
record.errors.add(attribute_name, message)
end
end
end
end