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 empty? 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

empty?()

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

[Source]

        # File lib/sequel/model/errors.rb, line 24
    24:       def empty?
    25:         count == 0
    26:       end

full_messages()

Returns an array of fully-formatted error messages.

[Source]

        # File lib/sequel/model/errors.rb, line 29
    29:       def full_messages
    30:         inject([]) do |m, kv|
    31:           att, errors = *kv
    32:           errors.each {|e| m << "#{Array(att).join(ATTRIBUTE_JOINER)} #{e}"}
    33:           m
    34:         end
    35:       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 39
    39:       def on(att)
    40:         if v = fetch(att, nil) and !v.empty?
    41:           v
    42:         end
    43:       end

[Validate]