Class: Reorm::PresenceValidator
- Defined in:
- lib/reorm/validators/presence_validator.rb
Instance Attribute Summary
Attributes inherited from Validator
Instance Method Summary collapse
-
#initialize(*field) ⇒ PresenceValidator
constructor
A new instance of PresenceValidator.
- #validate(object) ⇒ Object
Constructor Details
#initialize(*field) ⇒ PresenceValidator
Returns a new instance of PresenceValidator.
7 8 9 |
# File 'lib/reorm/validators/presence_validator.rb', line 7 def initialize(*field) super("cannot be blank.", *field) end |
Instance Method Details
#validate(object) ⇒ Object
11 12 13 14 15 |
# File 'lib/reorm/validators/presence_validator.rb', line 11 def validate(object) if !field.exists?(object) || [nil, ""].include?(field.value(object)) object.errors.add(field.to_s, ) end end |