lib/validations/validates_length_of.rb in validatable-1.2.2 vs lib/validations/validates_length_of.rb in validatable-1.3.0
- old
+ new
@@ -1,19 +1,20 @@
module Validatable
class ValidatesLengthOf < ValidationBase #:nodoc:
- attr_accessor :minimum, :maximum, :is
- understands :minimum, :maximum, :is
+ option :minimum, :maximum, :is, :within
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 &&= within.include?(value.length) unless within.nil?
valid
end
end
end