lib/validations/validates_length_of.rb in validatable-1.2.1 vs lib/validations/validates_length_of.rb in validatable-1.2.2
- old
+ new
@@ -1,17 +1,19 @@
module Validatable
class ValidatesLengthOf < ValidationBase #:nodoc:
- attr_accessor :minimum, :maximum
+ attr_accessor :minimum, :maximum, :is
+ understands :minimum, :maximum, :is
def message
super || "is invalid"
end
def valid?(instance)
valid = true
value = instance.send(self.attribute) || ""
valid &&= value.length <= maximum unless maximum.nil?
valid &&= value.length >= minimum unless minimum.nil?
+ valid &&= value.length == is unless is.nil?
valid
end
end
end