Class: Sequel::Model::Validation::Errors

Class | Sequel::Model::Validation::Errors
In: | lib/sequel_model/validations.rb
Parent: | ::Hash

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

### Methods

add count full_messages new on

### Public Class methods

new()

Assign an array of messages for each attribute on access

[Source]

        # File lib/sequel_model/validations.rb, line 13
    13:         def initialize
    14:           super{|h,k| h[k] = []}
    15:         end

### Public Instance methods

add(att, msg)

Adds an error for the given attribute.

[Source]

        # File lib/sequel_model/validations.rb, line 18
    18:         def add(att, msg)
    19:           self[att] << msg
    20:         end

count()

Return the total number of error messages.

[Source]

        # File lib/sequel_model/validations.rb, line 23
    23:         def count
    24:           full_messages.length
    25:         end

full_messages()

Returns an array of fully-formatted error messages.

[Source]

        # File lib/sequel_model/validations.rb, line 28
    28:         def full_messages
    29:           inject([]) do |m, kv|
    30:             att, errors = *kv
    31:             errors.each {|e| m << "#{Array(att).join(' and ')} #{e}"}
    32:             m
    33:           end
    34:         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/validations.rb, line 38
    38:         def on(att)
    39:           self[att] if include?(att)
    40:         end

[Validate]