Class: Sequel::Model::Validation::Errors
- Defined in:
- lib/sequel_model/validations.rb
Overview
Validation::Errors represents validation errors, a simple hash subclass with a few convenience methods.
Instance Method Summary collapse
-
#add(att, msg) ⇒ Object
Adds an error for the given attribute.
-
#count ⇒ Object
Return the total number of error messages.
-
#full_messages ⇒ Object
Returns an array of fully-formatted error messages.
-
#initialize ⇒ Errors
constructor
Assign an array of messages for each attribute on access.
-
#on(att) ⇒ Object
Returns the array of errors for the given attribute, or nil if there are no errors for the attribute.
Methods inherited from Hash
#&, #case, #sql_expr, #sql_negate, #sql_or, #|, #~
Constructor Details
#initialize ⇒ Errors
Assign an array of messages for each attribute on access
13 14 15 |
# File 'lib/sequel_model/validations.rb', line 13 def initialize super{|h,k| h[k] = []} end |
Instance Method Details
#add(att, msg) ⇒ Object
Adds an error for the given attribute.
18 19 20 |
# File 'lib/sequel_model/validations.rb', line 18 def add(att, msg) self[att] << msg end |
#count ⇒ Object
Return the total number of error messages.
23 24 25 |
# File 'lib/sequel_model/validations.rb', line 23 def count .length end |
#full_messages ⇒ Object
Returns an array of fully-formatted error messages.
28 29 30 31 32 33 34 |
# File 'lib/sequel_model/validations.rb', line 28 def inject([]) do |m, kv| att, errors = *kv errors.each {|e| m << "#{Array(att).join(' and ')} #{e}"} m end end |
#on(att) ⇒ Object
Returns the array of errors for the given attribute, or nil if there are no errors for the attribute.
38 39 40 |
# File 'lib/sequel_model/validations.rb', line 38 def on(att) self[att] if include?(att) end |