Class: Veto::PresenceValidator

Inherits:
AttributeValidator show all
Defined in:
lib/veto/validators/presence_validator.rb

Instance Method Summary collapse

Methods inherited from AttributeValidator

#execute, #initialize

Methods inherited from AbstractValidator

#execute

Constructor Details

This class inherits a constructor from Veto::AttributeValidator

Instance Method Details

#validate(entity, attribute, value, errors, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/veto/validators/presence_validator.rb', line 5

def validate entity, attribute, value, errors, options={}
	msg = options.fetch(:message, :presence)
	on = options.fetch(:on, attribute)
	v = value.is_a?(String) ? value.gsub(/\s+/, '') : value

	if v.nil? || v.respond_to?(:empty?) && v.empty?
		errors.add(on, msg)
	end	
end