Encapsulates a list of validation errors.
Methods
Attributes
| [RW] | errors |
Public Class methods
[ show source ]
# File lib/glue/validation.rb, line 85
85: def initialize(errors = {})
86: @errors = errors
87: end
Public Instance methods
Alias for #on
[ show source ]
# File lib/glue/validation.rb, line 89
89: def add(attr, message)
90: (@errors[attr] ||= []) << message
91: end
[ show source ]
# File lib/glue/validation.rb, line 115
115: def clear
116: @errors.clear
117: end
Alias for #size
Yields each attribute and associated message.
[ show source ]
# File lib/glue/validation.rb, line 100
100: def each
101: @errors.each_key do |attr|
102: @errors[attr].each { |msg| yield attr, msg }
103: end
104: end
[ show source ]
# File lib/glue/validation.rb, line 111
111: def empty?
112: @errors.empty?
113: end
[ show source ]
# File lib/glue/validation.rb, line 123
123: def join(glue)
124: @errors.to_a.join(glue)
125: end
This method is also aliased as
[]
[ show source ]
# File lib/glue/validation.rb, line 93
93: def on(attr)
94: @errors[attr]
95: end
This method is also aliased as
count
[ show source ]
# File lib/glue/validation.rb, line 106
106: def size
107: @errors.size
108: end
[ show source ]
# File lib/glue/validation.rb, line 119
119: def to_a
120: @errors.inject([]) { |a, kv| a << kv }
121: end