class Sequel::Model::Errors

with a few convenience methods.
Errors represents validation errors, a simple hash subclass

def [](k)

error messages.
to add new error messages, and +on+ to check existing
Using this message is discouraged in new code, use +add+
Assign an array of messages for each attribute on access.
def [](k)
  has_key?(k) ? super : (self[k] = [])
end

def add(att, msg)

errors.add(:name, 'is not valid') if name == 'invalid'

Adds an error for the given attribute.
def add(att, msg)
  self[att] << msg
end

def count

errors.count # => 3

Return the total number of error messages.
def count
  values.inject(0){|m, v| m + v.length}
end

def empty?

Return true if there are no error messages, false otherwise.
def empty?
  count == 0
end

def full_messages

# 'hometown is not at least 2 letters']
# => ['name is not valid',
errors.full_messages

Returns an array of fully-formatted error messages.
def full_messages
  inject([]) do |m, kv| 
    att, errors = *kv
    errors.each {|e| m << (e.is_a?(LiteralString) ? e : "#{Array(att).join(ATTRIBUTE_JOINER)} #{e}")}
    m
  end
end

def on(att)

errors.on(:id) # => nil
errors.on(:name) # => ['name is not valid']

if there are no errors for the attribute.
Returns the array of errors for the given attribute, or nil
def on(att)
  if v = fetch(att, nil) and !v.empty?
    v
  end
end