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
- .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.
16 17 18 19 20 21 |
# File 'lib/event_router/event.rb', line 16 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
44 45 46 |
# File 'lib/event_router/event.rb', line 44 def deliver_to(name, opts = {}) destinations[name] = EventRouter::Destination.new(name, **opts) end |
.inherited(base) ⇒ Object
39 40 41 42 |
# File 'lib/event_router/event.rb', line 39 def inherited(base) base.destinations = destinations.dup super end |
.publish(**attrs) ⇒ Object
48 49 50 |
# File 'lib/event_router/event.rb', line 48 def publish(**attrs) EventRouter.publish(new(**attrs)) end |
.publish_async(**attrs) ⇒ Object
52 53 54 |
# File 'lib/event_router/event.rb', line 52 def publish_async(**attrs) EventRouter.publish_async(new(**attrs)) end |
Instance Method Details
#name ⇒ Object
34 35 36 |
# File 'lib/event_router/event.rb', line 34 def name self.class.name.demodulize.underscore end |
#to_hash ⇒ Object Also known as: to_h
23 24 25 26 27 28 29 30 |
# File 'lib/event_router/event.rb', line 23 def to_hash { uid: uid, correlation_id: correlation_id, payload: payload, created_at: created_at } end |