Class: Brcobranca::Util::Errors
- Inherits:
-
Object
- Object
- Brcobranca::Util::Errors
- 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
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Instance Method Summary collapse
- #add(attribute, message = :invalid, options = {}) ⇒ Object
- #full_messages ⇒ Object (also: #to_a)
- #generate_message(attribute, type = :invalid, _options = {}) ⇒ Object
-
#initialize(base) ⇒ Errors
constructor
A new instance of Errors.
- #size ⇒ Object (also: #count)
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
#details ⇒ Object (readonly)
Returns the value of attribute details.
11 12 13 |
# File 'lib/brcobranca/util/errors.rb', line 11 def details @details end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
11 12 13 |
# File 'lib/brcobranca/util/errors.rb', line 11 def @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, = :invalid, = {}) = .call if .respond_to?(:call) detail = normalize_detail(, ) = (attribute, , ) details[attribute.to_sym] << detail [attribute.to_sym] << end |
#full_messages ⇒ Object Also known as: to_a
36 37 38 |
# File 'lib/brcobranca/util/errors.rb', line 36 def @messages.values.flatten end |
#generate_message(attribute, type = :invalid, _options = {}) ⇒ Object
32 33 34 |
# File 'lib/brcobranca/util/errors.rb', line 32 def (attribute, type = :invalid, = {}) :"errors.attributes.#{attribute}.#{type}" end |
#size ⇒ Object Also known as: count
27 28 29 |
# File 'lib/brcobranca/util/errors.rb', line 27 def size @messages.values.flatten.size end |