Class: N::Validation::Errors

Inherits:
Object
  • Object
show all
Defined in:
lib/glue/validation.rb

Overview

Encapsulates a list of validation errors.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeErrors

Returns a new instance of Errors.



66
67
68
# File 'lib/glue/validation.rb', line 66

def initialize
	@errors = {}
end

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



56
57
58
# File 'lib/glue/validation.rb', line 56

def errors
  @errors
end

Instance Method Details

#add(attr, message) ⇒ Object



70
71
72
# File 'lib/glue/validation.rb', line 70

def add(attr, message)
	(@errors[attr] ||= []) << message
end

#clearObject



96
97
98
# File 'lib/glue/validation.rb', line 96

def clear
	@errors.clear
end

#eachObject

Yields each attribute and associated message.



81
82
83
84
85
# File 'lib/glue/validation.rb', line 81

def each
	@errors.each_key do |attr| 
		@errors[attr].each { |msg| yield attr, msg }
	end
end

#empty?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/glue/validation.rb', line 92

def empty?
	@errors.empty?
end

#on(attr) ⇒ Object Also known as: []



74
75
76
# File 'lib/glue/validation.rb', line 74

def on(attr)
	@errors[attr]
end

#sizeObject Also known as: count



87
88
89
# File 'lib/glue/validation.rb', line 87

def size
	@errors.size
end