Class: Validatable::ValidatesPresenceOf
- Inherits:
-
ValidationBase
- Object
- ValidationBase
- Validatable::ValidatesPresenceOf
- Defined in:
- lib/validatable/validations/validates_presence_of.rb
Overview
:nodoc:
Instance Attribute Summary
Attributes inherited from ValidationBase
#after_validate, #allow_blank, #allow_nil, #attribute, #if, #klass
Instance Method Summary collapse
Methods inherited from ValidationBase
Constructor Details
This class inherits a constructor from Validatable::ValidationBase
Instance Method Details
#message(instance) ⇒ Object
12 13 14 |
# File 'lib/validatable/validations/validates_presence_of.rb', line 12 def (instance) super || "can't be empty" end |
#valid?(instance) ⇒ Boolean
3 4 5 6 7 8 9 10 |
# File 'lib/validatable/validations/validates_presence_of.rb', line 3 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 |