Class: Veto::MaxLengthCheck

Inherits:
AttributeCheck show all
Defined in:
lib/veto/checks/max_length_check.rb

Instance Method Summary collapse

Methods inherited from AttributeCheck

#call, #initialize

Methods inherited from Check

#call

Constructor Details

This class inherits a constructor from Veto::AttributeCheck

Instance Method Details

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



3
4
5
6
7
8
9
10
11
# File 'lib/veto/checks/max_length_check.rb', line 3

def check(attribute, value, errors, options={})
	max = options.fetch(:with)
	message = options.fetch(:message, :max_length)
	on = options.fetch(:on, attribute)
	
	if value.nil? || value.length > max
		errors.add(on, message, max)
	end
end