Class: EventRouter::Event
- Inherits:
-
Object
- Object
- EventRouter::Event
- Defined in:
- lib/event_router/event.rb
Instance Attribute Summary collapse
-
#correlation_id ⇒ Object
Returns the value of attribute correlation_id.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#uid ⇒ Object
readonly
Returns the value of attribute uid.
Class Method Summary collapse
- .deliver_to(name, opts = {}) ⇒ Object
- .event_options(opts) ⇒ Object
- .inherited(base) ⇒ Object
- .publish(**attrs) ⇒ Object
- .publish_async(**attrs) ⇒ Object
Instance Method Summary collapse
-
#initialize(uid: SecureRandom.uuid, correlation_id: SecureRandom.uuid, created_at: Time.now, **payload) ⇒ Event
constructor
A new instance of Event.
- #name ⇒ Object
- #to_hash ⇒ Object (also: #to_h)
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_id ⇒ Object
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_at ⇒ Object (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 |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
11 12 13 |
# File 'lib/event_router/event.rb', line 11 def payload @payload end |
#uid ⇒ Object (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 (opts) self. = 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
#name ⇒ Object
35 36 37 |
# File 'lib/event_router/event.rb', line 35 def name self.class.name.demodulize.underscore end |
#to_hash ⇒ Object 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 |