Class: Validation::Errors
- Inherits:
-
Object
- Object
- Validation::Errors
- Defined in:
- lib/sequel_model/validations.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.
-
#each(&block) ⇒ Object
Iterates over 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.
-
#size ⇒ Object
Returns size of errors array.
Constructor Details
#initialize ⇒ Errors
Initializes a new instance of validation errors.
45 46 47 |
# File 'lib/sequel_model/validations.rb', line 45 def initialize @errors = Hash.new {|h, k| h[k] = []} end |
Instance Method Details
#add(att, msg) ⇒ Object
Adds an error for the given attribute.
50 51 52 |
# File 'lib/sequel_model/validations.rb', line 50 def add(att, msg) @errors[att] << msg end |
#clear ⇒ Object
Clears all errors.
55 56 57 |
# File 'lib/sequel_model/validations.rb', line 55 def clear @errors.clear end |
#each(&block) ⇒ Object
Iterates over errors
60 61 62 |
# File 'lib/sequel_model/validations.rb', line 60 def each(&block) @errors.each(&block) end |
#empty? ⇒ Boolean
Returns true if no errors are stored.
65 66 67 |
# File 'lib/sequel_model/validations.rb', line 65 def empty? @errors.empty? end |
#full_messages ⇒ Object
Returns an array of fully-formatted error messages.
70 71 72 73 74 75 |
# File 'lib/sequel_model/validations.rb', line 70 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.
78 79 80 |
# File 'lib/sequel_model/validations.rb', line 78 def on(att) @errors[att] end |
#size ⇒ Object
Returns size of errors array
84 85 86 |
# File 'lib/sequel_model/validations.rb', line 84 def size @errors.size end |