Class: EventRouter::Event

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uid: SecureRandom.uuid, correlation_id: SecureRandom.uuid, created_at: Time.now, **payload) ⇒ Event

Returns a new instance of Event.



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

def initialize(uid: SecureRandom.uuid, correlation_id: SecureRandom.uuid, created_at: Time.now, **payload)
  @uid            = uid
  @correlation_id = correlation_id
  @created_at     = created_at
  @payload        = payload
end

Instance Attribute Details

#correlation_idObject

Returns the value of attribute correlation_id.



12
13
14
# File 'lib/event_router/event.rb', line 12

def correlation_id
  @correlation_id
end

#created_atObject (readonly)

Returns the value of attribute created_at.



11
12
13
# File 'lib/event_router/event.rb', line 11

def created_at
  @created_at
end

#payloadObject (readonly)

Returns the value of attribute payload.



11
12
13
# File 'lib/event_router/event.rb', line 11

def payload
  @payload
end

#uidObject (readonly)

Returns the value of attribute uid.



11
12
13
# File 'lib/event_router/event.rb', line 11

def uid
  @uid
end

Class Method Details

.deliver_to(name, opts = {}) ⇒ Object



45
46
47
# File 'lib/event_router/event.rb', line 45

def deliver_to(name, opts = {})
  destinations[name] = EventRouter::Destination.new(name, **opts)
end

.event_options(opts) ⇒ Object



49
50
51
# File 'lib/event_router/event.rb', line 49

def event_options(opts)
  self.options = opts
end

.inherited(base) ⇒ Object



40
41
42
43
# File 'lib/event_router/event.rb', line 40

def inherited(base)
  base.destinations = destinations.dup
  super
end

.publish(**attrs) ⇒ Object



53
54
55
# File 'lib/event_router/event.rb', line 53

def publish(**attrs)
  EventRouter.publish(new(**attrs))
end

.publish_async(**attrs) ⇒ Object



57
58
59
# File 'lib/event_router/event.rb', line 57

def publish_async(**attrs)
  EventRouter.publish_async(new(**attrs))
end

Instance Method Details

#nameObject



35
36
37
# File 'lib/event_router/event.rb', line 35

def name
  self.class.name.demodulize.underscore
end

#to_hashObject Also known as: to_h



24
25
26
27
28
29
30
31
# File 'lib/event_router/event.rb', line 24

def to_hash
  {
    uid: uid,
    correlation_id: correlation_id,
    payload: payload,
    created_at: created_at
  }
end