def validate_attribute record, attribute_name, value_or_values
each_value(value_or_values) do |value|
length = value.respond_to?(:length) ? value.length : value.to_s.length
if exact = options[:exactly]
unless length == exact
record.errors.add(attribute_name, wrong_length(exact, length))
end
end
if within = options[:within]
if length < within.first
record.errors.add(attribute_name, too_short(within.first, length))
end
if length > within.last
record.errors.add(attribute_name, too_long(within.last, length))
end
end
if min = options[:minimum]
if length < min
record.errors.add(attribute_name, too_short(min, length))
end
end
if max = options[:maximum]
if length > max
record.errors.add(attribute_name, too_long(max, length))
end
end
end
end