Class: ObjectValidator::Errors

Inherits:
Object
  • Object
show all
Defined in:
lib/object_validator/errors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeErrors

Returns a new instance of Errors.



5
6
7
8
# File 'lib/object_validator/errors.rb', line 5

def initialize
  @all = {}
  @full_messages = []
end

Instance Attribute Details

#allObject

Returns the value of attribute all.



3
4
5
# File 'lib/object_validator/errors.rb', line 3

def all
  @all
end

Instance Method Details

#add(name, msg) ⇒ Object



10
11
12
# File 'lib/object_validator/errors.rb', line 10

def add(name, msg)
  (@all[name] ||= []) << msg
end

#full_messagesObject



14
15
16
17
18
19
20
# File 'lib/object_validator/errors.rb', line 14

def full_messages
  @all.map do |error|
    attr, errors = *error
    errors.each { |e| @full_messages << "#{attr.to_s.capitalize} #{e}." }
  end
  @full_messages
end