Class: Brcobranca::Util::Errors

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

Constant Summary collapse

CALLBACKS_OPTIONS =
%i[if unless on allow_nil allow_blank strict].freeze
MESSAGE_OPTIONS =
[:message].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base) ⇒ Errors

Returns a new instance of Errors.



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

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.



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

def details
  @details
end

#messagesObject (readonly)

Returns the value of attribute messages.



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

def messages
  @messages
end

Instance Method Details

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



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

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



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

def full_messages
  @messages.values.flatten
end

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



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

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

#sizeObject Also known as: count



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

def size
  @messages.values.flatten.size
end