Sha256: 6b4c813e3e66409cfc24c160f70c448636ed8eea688131202a66f6e4ff2c1f97

Contents?: true

Size: 648 Bytes

Versions: 14

Compression:

Stored size: 648 Bytes

Contents

module Validatable
  class ValidatesLengthOf < ValidationBase #:nodoc:
    option :minimum, :maximum, :is, :within, :allow_nil
    
    def message(instance)
      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

14 entries across 14 versions & 2 rubygems

Version Path
mack-notifier-0.8.2 lib/gems/validatable-1.6.7/lib/validations/validates_length_of.rb
mack-notifier-0.8.3 lib/gems/validatable-1.6.7/lib/validations/validates_length_of.rb
mack-notifier-0.8.3.1 lib/gems/validatable-1.6.7/lib/validations/validates_length_of.rb
validatable-1.6.1 lib/validations/validates_length_of.rb
validatable-1.6.7 lib/validations/validates_length_of.rb
validatable-1.4.0 lib/validations/validates_length_of.rb
validatable-1.6.6 lib/validations/validates_length_of.rb
validatable-1.5.0 lib/validations/validates_length_of.rb
validatable-1.6.0 lib/validations/validates_length_of.rb
validatable-1.6.2 lib/validations/validates_length_of.rb
validatable-1.5.2 lib/validations/validates_length_of.rb
validatable-1.6.4 lib/validations/validates_length_of.rb
validatable-1.3.4 lib/validations/validates_length_of.rb
validatable-1.6.3 lib/validations/validates_length_of.rb