Class: Brcobranca::Util::Errors

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/brcobranca/util/errors.rb

Constant Summary collapse

CALLBACKS_OPTIONS =
[:if, :unless, :on, :allow_nil, :allow_blank, :strict]
MESSAGE_OPTIONS =
[:message]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base) ⇒ Errors

Returns a new instance of Errors.


12
13
14
15
16
# File 'lib/brcobranca/util/errors.rb', line 12

def initialize(base)
  @base     = base
  @messages = apply_default_array({})
  @details = apply_default_array({})
end

Instance Attribute Details

#detailsObject (readonly)

Returns the value of attribute details


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

def details
  @details
end

#messagesObject (readonly)

Returns the value of attribute messages


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

def messages
  @messages
end

Instance Method Details

#add(attribute, message = :invalid, options = {}) ⇒ Object


18
19
20
21
22
23
24
# File 'lib/brcobranca/util/errors.rb', line 18

def add(attribute, message = :invalid, options = {})
  message = message.call if message.respond_to?(:call)
  detail  = normalize_detail(message, options)
  message = normalize_message(attribute, message, options)
  details[attribute.to_sym]  << detail
  messages[attribute.to_sym] << message
end

#full_messagesObject Also known as: to_a


35
36
37
# File 'lib/brcobranca/util/errors.rb', line 35

def full_messages
  @messages.values.flatten
end

#generate_message(attribute, type = :invalid, options = {}) ⇒ Object


31
32
33
# File 'lib/brcobranca/util/errors.rb', line 31

def generate_message(attribute, type = :invalid, options = {})
  :"errors.attributes.#{attribute}.#{type}"
end

#sizeObject Also known as: count


26
27
28
# File 'lib/brcobranca/util/errors.rb', line 26

def size
  @messages.values.flatten.size
end