Class: Validation::Errors

Class | Validation::Errors
In: | lib/assistance/validation.rb
Parent: | Object

Validation::Errors represents validation errors.

### Methods

[] add clear empty? full_messages new on

### Public Class methods

new()

Initializes a new instance of validation errors.

[Source]

        # File lib/assistance/validation.rb, line 42
    42:     def initialize
    43:       @errors = Hash.new {|h, k| h[k] = []}
    44:     end

### Public Instance methods

[](att)

Alias for on

add(att, msg)

Adds an error for the given attribute.

[Source]

        # File lib/assistance/validation.rb, line 63
    63:     def add(att, msg)
    64:       @errors[att] << msg
    65:     end

clear()

Clears all errors.

[Source]

        # File lib/assistance/validation.rb, line 52
    52:     def clear
    53:       @errors.clear
    54:     end

empty?()

Returns true if no errors are stored.

[Source]

        # File lib/assistance/validation.rb, line 47
    47:     def empty?
    48:       @errors.empty?
    49:     end

full_messages()

Returns an array of fully-formatted error messages.

[Source]

        # File lib/assistance/validation.rb, line 68
    68:     def full_messages
    69:       @errors.inject([]) do |m, kv| att, errors = *kv
    70:         errors.each {|e| m << "#{att} #{e}"}
    71:         m
    72:       end
    73:     end

on(att)

Returns the errors for the given attribute.

[Source]

        # File lib/assistance/validation.rb, line 57
    57:     def on(att)
    58:       @errors[att]
    59:     end

[Validate]