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.
-
#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 errors for the given 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
10 11 12 |
# File 'lib/sequel_model/validations.rb', line 10 def initialize super{|h,k| h[k] = []} end |
Instance Method Details
#add(att, msg) ⇒ Object
Adds an error for the given attribute.
15 16 17 |
# File 'lib/sequel_model/validations.rb', line 15 def add(att, msg) self[att] << msg end |
#full_messages ⇒ Object
Returns an array of fully-formatted error messages.
20 21 22 23 24 25 26 |
# File 'lib/sequel_model/validations.rb', line 20 def inject([]) do |m, kv| att, errors = *kv errors.each {|e| m << "#{att} #{e}"} m end end |
#on(att) ⇒ Object
Returns the errors for the given attribute.
29 30 31 |
# File 'lib/sequel_model/validations.rb', line 29 def on(att) self[att] end |