Class: Validation::Errors
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.
42 43 44 |
# File 'lib/assistance/validation.rb', line 42 def initialize @errors = Hash.new {|h, k| h[k] = []} end |
Instance Method Details
#add(att, msg) ⇒ Object
Adds an error for the given attribute.
63 64 65 |
# File 'lib/assistance/validation.rb', line 63 def add(att, msg) @errors[att] << msg end |
#clear ⇒ Object
Clears all errors.
52 53 54 |
# File 'lib/assistance/validation.rb', line 52 def clear @errors.clear end |
#empty? ⇒ Boolean
Returns true if no errors are stored.
47 48 49 |
# File 'lib/assistance/validation.rb', line 47 def empty? @errors.empty? end |
#full_messages ⇒ Object
Returns an array of fully-formatted error messages.
68 69 70 71 72 73 |
# File 'lib/assistance/validation.rb', line 68 def @errors.inject([]) 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.
57 58 59 |
# File 'lib/assistance/validation.rb', line 57 def on(att) @errors[att] end |