Sha256: 1384def15c0563a49a5a12196367dbc990e020c8004101c0cc45f463902c25f2

Contents?: true

Size: 480 Bytes

Versions: 25

Compression:

Stored size: 480 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.blank?
      
      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

25 entries across 25 versions & 8 rubygems

Version Path
hashrocket-validatable-1.7.2 lib/validations/validates_presence_of.rb
hashrocket-validatable-1.7.4 lib/validations/validates_presence_of.rb
jnunemaker-validatable-1.7.0 lib/validations/validates_presence_of.rb
jnunemaker-validatable-1.7.1 lib/validations/validates_presence_of.rb
jnunemaker-validatable-1.7.2 lib/validations/validates_presence_of.rb
vizjerai-validatable-1.8.0 lib/validations/validates_presence_of.rb
vizjerai-validatable-1.9.0 lib/validations/validates_presence_of.rb
lgustafson-validatable-1.8.7 lib/validatable/validations/validates_presence_of.rb
lgustafson-validatable-1.8.6 lib/validatable/validations/validates_presence_of.rb
np422-validatable-1.8.5 lib/validatable/validations/validates_presence_of.rb
erotte-validatable-1.8.5 lib/validatable/validations/validates_presence_of.rb
mattmatt-validatable-1.8.3 lib/validatable/validations/validates_presence_of.rb
jnunemaker-validatable-1.8.4 lib/validatable/validations/validates_presence_of.rb
jnunemaker-validatable-1.8.3 lib/validatable/validations/validates_presence_of.rb
jnunemaker-validatable-1.8.2 lib/validatable/validations/validates_presence_of.rb
jnunemaker-validatable-1.1.10 lib/validatable/validations/validates_presence_of.rb
jnunemaker-validatable-1.1.9 lib/validatable/validations/validates_presence_of.rb
jnunemaker-validatable-1.8.1 lib/validatable/validations/validates_presence_of.rb
durran-validatable-1.8.2 lib/validations/validates_presence_of.rb
durran-validatable-1.8.1 lib/validations/validates_presence_of.rb