Class: Sequel::Model::Errors

Class | Sequel::Model::Errors
In: | lib/sequel/model/errors.rb
Parent: | ::Hash

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

### Methods

[] add count full_messages on

### Constants

ATTRIBUTE_JOINER | = | ' and '.freeze

### Public Instance methods

[](k)

Assign an array of messages for each attribute on access

[Source]

        # File lib/sequel/model/errors.rb, line 9
     9:       def [](k)
    10:         has_key?(k) ? super : (self[k] = [])
    11:       end

add(att, msg)

Adds an error for the given attribute.

[Source]

        # File lib/sequel/model/errors.rb, line 14
    14:       def add(att, msg)
    15:         self[att] << msg
    16:       end

count()

Return the total number of error messages.

[Source]

        # File lib/sequel/model/errors.rb, line 19
    19:       def count
    20:         values.inject(0){|m, v| m + v.length}
    21:       end

full_messages()

Returns an array of fully-formatted error messages.

[Source]

        # File lib/sequel/model/errors.rb, line 24
    24:       def full_messages
    25:         inject([]) do |m, kv|
    26:           att, errors = *kv
    27:           errors.each {|e| m << "#{Array(att).join(ATTRIBUTE_JOINER)} #{e}"}
    28:           m
    29:         end
    30:       end

on(att)

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

[Source]

        # File lib/sequel/model/errors.rb, line 34
    34:       def on(att)
    35:         self[att] if has_key?(att)
    36:       end

[Validate]