Class: Sequel::Model::Validation::Errors

Inherits:
Hash show all
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

Methods inherited from Hash

#&, #case, #sql_expr, #sql_negate, #sql_or, #|, #~

Constructor Details

#initializeErrors

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_messagesObject

Returns an array of fully-formatted error messages.



20
21
22
23
24
25
26
# File 'lib/sequel_model/validations.rb', line 20

def full_messages
  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