Sha256: 229ac06c9ad4851eb082464d318442f2e57cbf09ccf6d2beb5213fcbdc348d0a
Contents?: true
Size: 639 Bytes
Versions: 1
Compression:
Stored size: 639 Bytes
Contents
module Validatable class ValidatesLengthOf < ValidationBase #:nodoc: option :minimum, :maximum, :is, :within, :allow_nil def message super || "is invalid" end def valid?(instance) valid = true value = instance.send(self.attribute) if value.nil? return true if allow_nil value = "" end 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
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
validatable-1.3.2 | lib/validations/validates_length_of.rb |