Sha256: f4ef5676363a3b385e84d836096aa36e75b4c20be0d33c44318b1ff1796e6fbe

Contents?: true

Size: 525 Bytes

Versions: 2

Compression:

Stored size: 525 Bytes

Contents

module Validatable 
  class ValidatesPresenceOf < ValidationBase #:nodoc:
    def valid?(instance)
      value = instance.send(self.attribute)
      return true if allow_nil && value.nil?
      return true if allow_blank && (!value or (value.respond_to?(:empty?) and value.empty?))
      
      return false if instance.send(self.attribute).nil?
      value.respond_to?(:strip) ? instance.send(self.attribute).strip.length != 0 : true
    end
    
    def message(instance)
      super || "can't be empty"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
validatable2-0.0.2 lib/validatable/validations/validates_presence_of.rb
validatable2-0.0.1 lib/validatable/validations/validates_presence_of.rb