Class: Validation::Errors

Inherits:
Object
  • Object
show all
Defined in:
lib/rcap/validation.rb

Overview

Validation::Errors represents validation errors.

Instance Method Summary collapse

Constructor Details

#initializeErrors

Initializes a new instance of validation errors.



47
48
49
# File 'lib/rcap/validation.rb', line 47

def initialize
  @errors = Hash.new { |h, k| h[k] = [] }
end

Instance Method Details

#add(att, msg) ⇒ Object

Adds an error for the given attribute.



68
69
70
# File 'lib/rcap/validation.rb', line 68

def add(att, msg)
  @errors[att] << msg
end

#clearObject

Clears all errors.



57
58
59
# File 'lib/rcap/validation.rb', line 57

def clear
  @errors.clear
end

#empty?Boolean

Returns true if no errors are stored.

Returns:

  • (Boolean)


52
53
54
# File 'lib/rcap/validation.rb', line 52

def empty?
  @errors.empty?
end

#full_messagesObject

Returns an array of fully-formatted error messages.



73
74
75
76
77
78
# File 'lib/rcap/validation.rb', line 73

def full_messages
  @errors.reduce([]) do |m, kv| att, errors = *kv
                                errors.each { |e| m << "#{att} #{e}" }
                                m
  end
end

#on(att) ⇒ Object Also known as: []

Returns the errors for the given attribute.



62
63
64
# File 'lib/rcap/validation.rb', line 62

def on(att)
  @errors[att]
end