Class: Validation::Errors
- Inherits:
-
Object
- Object
- Validation::Errors
- Defined in:
- lib/rcap/validation.rb
Overview
Validation::Errors represents validation errors.
Instance Method Summary collapse
-
#add(att, msg) ⇒ Object
Adds an error for the given attribute.
-
#clear ⇒ Object
Clears all errors.
-
#empty? ⇒ Boolean
Returns true if no errors are stored.
-
#full_messages ⇒ Object
Returns an array of fully-formatted error messages.
-
#initialize ⇒ Errors
constructor
Initializes a new instance of validation errors.
-
#on(att) ⇒ Object
(also: #[])
Returns the errors for the given attribute.
Constructor Details
#initialize ⇒ Errors
Initializes a new instance of validation errors.
47 48 49 |
# File 'lib/rcap/validation.rb', line 47 def initialize @errors = Hash.new { |h, k| h[k] = [] } end |
Instance Method Details
#add(att, msg) ⇒ Object
Adds an error for the given attribute.
68 69 70 |
# File 'lib/rcap/validation.rb', line 68 def add(att, msg) @errors[att] << msg end |
#clear ⇒ Object
Clears all errors.
57 58 59 |
# File 'lib/rcap/validation.rb', line 57 def clear @errors.clear end |
#empty? ⇒ Boolean
Returns true if no errors are stored.
52 53 54 |
# File 'lib/rcap/validation.rb', line 52 def empty? @errors.empty? end |
#full_messages ⇒ Object
Returns an array of fully-formatted error messages.
73 74 75 76 77 78 |
# File 'lib/rcap/validation.rb', line 73 def @errors.reduce([]) do |m, kv| att, errors = *kv errors.each { |e| m << "#{att} #{e}" } m end end |
#on(att) ⇒ Object Also known as: []
Returns the errors for the given attribute.
62 63 64 |
# File 'lib/rcap/validation.rb', line 62 def on(att) @errors[att] end |