class Sequel::Model::Errors
with a few convenience methods.
Errors represents validation errors, a simple hash subclass
def [](k)
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)
Adds an error for the given attribute.
def add(att, msg) self[att] << msg end
def count
Return the total number of error messages.
def count values.inject(0){|m, v| m + v.length} end
def empty?
def empty? count == 0 end
def full_messages
# => ['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(: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