Parent

Class/Module Index [+]

Quicksearch

Sequel::Model::Errors

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

Constants

ATTRIBUTE_JOINER

Public Instance Methods

[](k) click to toggle source

Assign an array of messages for each attribute on access

# File lib/sequel/model/errors.rb, line 9
def [](k)
  has_key?(k) ? super : (self[k] = [])
end
add(att, msg) click to toggle source

Adds an error for the given attribute.

# File lib/sequel/model/errors.rb, line 14
def add(att, msg)
  self[att] << msg
end
count() click to toggle source

Return the total number of error messages.

# File lib/sequel/model/errors.rb, line 19
def count
  values.inject(0){|m, v| m + v.length}
end
empty?() click to toggle source

Return true if there are no error messages, false otherwise.

# File lib/sequel/model/errors.rb, line 24
def empty?
  count == 0
end
full_messages() click to toggle source

Returns an array of fully-formatted error messages.

# File lib/sequel/model/errors.rb, line 29
def full_messages
  inject([]) do |m, kv| 
    att, errors = *kv
    errors.each {|e| m << "#{Array(att).join(ATTRIBUTE_JOINER)} #{e}"}
    m
  end
end
on(att) click to toggle source

Returns the array of errors for the given attribute, or nil if there are no errors for the attribute.

# File lib/sequel/model/errors.rb, line 39
def on(att)
  if v = fetch(att, nil) and !v.empty?
    v
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.