Class: Reins::Model::Errors

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

Instance Method Summary collapse

Constructor Details

#initializeErrors

Returns a new instance of Errors.



4
5
6
# File 'lib/reins/model/errors.rb', line 4

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

Instance Method Details

#[](attr) ⇒ Object



12
13
14
# File 'lib/reins/model/errors.rb', line 12

def [](attr)
  @messages[attr.to_sym]
end

#add(attr, message) ⇒ Object



8
9
10
# File 'lib/reins/model/errors.rb', line 8

def add(attr, message)
  @messages[attr.to_sym] << message
end

#clearObject



20
21
22
# File 'lib/reins/model/errors.rb', line 20

def clear
  @messages.clear
end

#empty?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/reins/model/errors.rb', line 16

def empty?
  @messages.values.all?(&:empty?)
end

#full_messagesObject



24
25
26
27
28
29
# File 'lib/reins/model/errors.rb', line 24

def full_messages
  @messages.flat_map do |attr, msgs|
    label = humanize(attr.to_s)
    msgs.map { |m| "#{label} #{m}" }
  end
end