Class: Informator::Event
- Inherits:
-
Object
- Object
- Informator::Event
- Defined in:
- lib/informator/event.rb
Overview
Class Event provides an immutable container for hash of some attributes, to which a type is attached. It also contains an array of human-readable messages describing the event.
The primary goal of events is folding attributes to be returned and/or sent between various objects into unified format.
Instance Attribute Summary collapse
-
#attributes ⇒ Hash
readonly
The event-specific attributes.
-
#messages ⇒ Array<String>
readonly
Human-readable messages, describing the event.
-
#type ⇒ Symbol
readonly
The type of the event.
Class Method Summary collapse
-
.[](*args) ⇒ Informator::Event
Builds the event.
Instance Method Summary collapse
-
#[](type, messages, attributes) ⇒ Informator::Event
Builds the event.
-
#initialize(type, *messages, **attributes) ⇒ Event
constructor
A new instance of Event.
Constructor Details
#initialize(type, *messages, **attributes) ⇒ Event
55 56 57 58 59 60 |
# File 'lib/informator/event.rb', line 55 def initialize(type, *, **attributes) @type = type.to_sym @messages = .flatten.map(&:to_s) @attributes = attributes IceNine.deep_freeze(self) end |
Instance Attribute Details
#attributes ⇒ Hash (readonly)
33 34 35 |
# File 'lib/informator/event.rb', line 33 def attributes @attributes end |
#messages ⇒ Array<String> (readonly)
39 40 41 |
# File 'lib/informator/event.rb', line 39 def @messages end |
#type ⇒ Symbol (readonly)
27 28 29 |
# File 'lib/informator/event.rb', line 27 def type @type end |
Class Method Details
.[](*args) ⇒ Informator::Event
Builds the event
50 51 52 |
# File 'lib/informator/event.rb', line 50 def self.[](*args) new(*args) end |
Instance Method Details
#[](type, messages, attributes) ⇒ Informator::Event
Builds the event
50 51 52 |
# File 'lib/informator/event.rb', line 50 def self.[](*args) new(*args) end |