Class: Steroids::Support::NoticableMethods::NoticableCollection
- Inherits:
-
Object
- Object
- Steroids::Support::NoticableMethods::NoticableCollection
- Defined in:
- lib/steroids/support/noticable_methods.rb
Overview
Noticable collection
Constant Summary collapse
- NOTICABLE_TYPES =
i[errors notices]
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
Instance Method Summary collapse
- #add(message, exception = nil) ⇒ Object (also: #<<)
- #full_messages ⇒ Object
-
#initialize(collection_type) ⇒ NoticableCollection
constructor
A new instance of NoticableCollection.
- #merge(errors) ⇒ Object
Constructor Details
#initialize(collection_type) ⇒ NoticableCollection
Returns a new instance of NoticableCollection.
30 31 32 33 |
# File 'lib/steroids/support/noticable_methods.rb', line 30 def initialize(collection_type) @collection_type = NOTICABLE_TYPES.cast(collection_type) @collection = [] end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
26 27 28 |
# File 'lib/steroids/support/noticable_methods.rb', line 26 def collection @collection end |
Instance Method Details
#add(message, exception = nil) ⇒ Object Also known as: <<
35 36 37 38 39 40 41 42 |
# File 'lib/steroids/support/noticable_methods.rb', line 35 def add(, exception = nil) nil.tap do @collection << { message: .typed!(String), exception: exception } end end |
#full_messages ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/steroids/support/noticable_methods.rb', line 54 def if @collection.any? @collection.map do |error| error[:message] end.join("\n").presence end end |
#merge(errors) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/steroids/support/noticable_methods.rb', line 44 def merge(errors) nil.tap do errors.each do |error| @collection << error end end end |