Class: Glue::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 = {}) ⇒ Errors
constructor
A new instance of Errors.
- #join(glue) ⇒ Object
- #on(attr) ⇒ Object (also: #[])
- #size ⇒ Object (also: #count)
- #to_a ⇒ Object
Constructor Details
#initialize(errors = {}) ⇒ Errors
Returns a new instance of Errors.
85 86 87 |
# File 'lib/more/facets/validation.rb', line 85 def initialize(errors = {}) @errors = errors end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
73 74 75 |
# File 'lib/more/facets/validation.rb', line 73 def errors @errors end |
Instance Method Details
#add(attr, message) ⇒ Object
89 90 91 |
# File 'lib/more/facets/validation.rb', line 89 def add(attr, ) (@errors[attr] ||= []) << end |
#clear ⇒ Object
115 116 117 |
# File 'lib/more/facets/validation.rb', line 115 def clear @errors.clear end |
#each ⇒ Object
Yields each attribute and associated message.
100 101 102 103 104 |
# File 'lib/more/facets/validation.rb', line 100 def each @errors.each_key do |attr| @errors[attr].each { |msg| yield attr, msg } end end |
#empty? ⇒ Boolean
111 112 113 |
# File 'lib/more/facets/validation.rb', line 111 def empty? @errors.empty? end |
#join(glue) ⇒ Object
123 124 125 |
# File 'lib/more/facets/validation.rb', line 123 def join(glue) @errors.to_a.join(glue) end |
#on(attr) ⇒ Object Also known as: []
93 94 95 |
# File 'lib/more/facets/validation.rb', line 93 def on(attr) @errors[attr] end |
#size ⇒ Object Also known as: count
106 107 108 |
# File 'lib/more/facets/validation.rb', line 106 def size @errors.size end |
#to_a ⇒ Object
119 120 121 |
# File 'lib/more/facets/validation.rb', line 119 def to_a @errors.inject([]) { |a, kv| a << kv } end |