Class: N::Validation::Errors
Overview
Encapsulates a list of validation errors.
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
Instance Method Summary collapse
- #add(attr, message) ⇒ Object
- #clear ⇒ Object
-
#each ⇒ Object
Yields each attribute and associated message.
- #empty? ⇒ Boolean
-
#initialize ⇒ Errors
constructor
A new instance of Errors.
- #on(attr) ⇒ Object (also: #[])
- #size ⇒ Object (also: #count)
Constructor Details
#initialize ⇒ Errors
Returns a new instance of Errors.
66 67 68 |
# File 'lib/glue/validation.rb', line 66 def initialize @errors = {} end |
Instance Attribute Details
#errors ⇒ Object
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, ) (@errors[attr] ||= []) << end |
#clear ⇒ Object
96 97 98 |
# File 'lib/glue/validation.rb', line 96 def clear @errors.clear end |
#each ⇒ Object
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
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 |
#size ⇒ Object Also known as: count
87 88 89 |
# File 'lib/glue/validation.rb', line 87 def size @errors.size end |