Class: Toot::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/toot/event.rb

Constant Summary collapse

DEFAULTS =
-> {
  {
    id: SecureRandom.uuid,
    timestamp: Time.now,
    payload: {},
  }
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Event

Returns a new instance of Event.



16
17
18
19
20
21
22
# File 'lib/toot/event.rb', line 16

def initialize(args={})
  args = DEFAULTS.().merge(_symbolize_keys(args))
  @id = args[:id]
  @timestamp = args[:timestamp]
  @payload = args[:payload]
  @channel = args[:channel]
end

Instance Attribute Details

#channelObject

Returns the value of attribute channel.



6
7
8
# File 'lib/toot/event.rb', line 6

def channel
  @channel
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/toot/event.rb', line 6

def id
  @id
end

#payloadObject

Returns the value of attribute payload.



6
7
8
# File 'lib/toot/event.rb', line 6

def payload
  @payload
end

#timestampObject

Returns the value of attribute timestamp.



6
7
8
# File 'lib/toot/event.rb', line 6

def timestamp
  @timestamp
end

Instance Method Details

#==(other) ⇒ Object



38
39
40
# File 'lib/toot/event.rb', line 38

def ==(other)
  self.id == other.id
end

#[](key) ⇒ Object



42
43
44
# File 'lib/toot/event.rb', line 42

def [](key)
  payload[key]
end

#publishObject



24
25
26
27
# File 'lib/toot/event.rb', line 24

def publish
  PublishesEvent.perform_async(to_h)
  self
end

#to_hObject



29
30
31
32
33
34
35
36
# File 'lib/toot/event.rb', line 29

def to_h
  {
    id: id,
    timestamp: timestamp,
    payload: payload,
    channel: channel,
  }
end