Class: Informator::Event

Inherits:
Object
  • Object
show all
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.

Examples:

event = Event[:success, "bingo!", foo: :bar]
# <Event @type=:success @messages=["bingo!"] @attributes={ :foo => :bar }>

event.frozen?
# => true

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, *messages, **attributes) ⇒ Event



55
56
57
58
59
60
# File 'lib/informator/event.rb', line 55

def initialize(type, *messages, **attributes)
  @type       = type.to_sym
  @messages   = messages.flatten.map(&:to_s)
  @attributes = attributes
  IceNine.deep_freeze(self)
end

Instance Attribute Details

#attributesHash (readonly)



33
34
35
# File 'lib/informator/event.rb', line 33

def attributes
  @attributes
end

#messagesArray<String> (readonly)



39
40
41
# File 'lib/informator/event.rb', line 39

def messages
  @messages
end

#typeSymbol (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