Class: Reorm::PresenceValidator

Inherits:
Validator show all
Defined in:
lib/reorm/validators/presence_validator.rb

Instance Attribute Summary

Attributes inherited from Validator

#field, #message

Instance Method Summary collapse

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, message)
  end
end