Class: Pgbus::Event
- Inherits:
-
Object
- Object
- Pgbus::Event
- Defined in:
- lib/pgbus/event.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
contextis the publisher's persisted ActiveSupport::CurrentAttributes (issue #431) in their stored form — { "Current" => serialized attrs } — or nil. -
#event_id ⇒ Object
readonly
contextis the publisher's persisted ActiveSupport::CurrentAttributes (issue #431) in their stored form — { "Current" => serialized attrs } — or nil. -
#headers ⇒ Object
readonly
contextis the publisher's persisted ActiveSupport::CurrentAttributes (issue #431) in their stored form — { "Current" => serialized attrs } — or nil. -
#payload ⇒ Object
readonly
contextis the publisher's persisted ActiveSupport::CurrentAttributes (issue #431) in their stored form — { "Current" => serialized attrs } — or nil. -
#published_at ⇒ Object
readonly
contextis the publisher's persisted ActiveSupport::CurrentAttributes (issue #431) in their stored form — { "Current" => serialized attrs } — or nil. -
#routing_key ⇒ Object
readonly
contextis the publisher's persisted ActiveSupport::CurrentAttributes (issue #431) in their stored form — { "Current" => serialized attrs } — or nil.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(event_id:, payload:, published_at: nil, routing_key: nil, headers: nil, context: nil) ⇒ Event
constructor
A new instance of Event.
- #to_h ⇒ Object
Constructor Details
#initialize(event_id:, payload:, published_at: nil, routing_key: nil, headers: nil, context: nil) ⇒ Event
Returns a new instance of Event.
13 14 15 16 17 18 19 20 |
# File 'lib/pgbus/event.rb', line 13 def initialize(event_id:, payload:, published_at: nil, routing_key: nil, headers: nil, context: nil) @event_id = event_id @payload = payload @published_at = published_at || Time.now.utc @routing_key = routing_key @headers = headers || {} @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
context is the publisher's persisted ActiveSupport::CurrentAttributes
(issue #431) in their stored form — { "Current" => serialized attrs } —
or nil. Handlers normally just read Current (it is restored around
handle); the raw form is here for tests and explicit access.
11 12 13 |
# File 'lib/pgbus/event.rb', line 11 def context @context end |
#event_id ⇒ Object (readonly)
context is the publisher's persisted ActiveSupport::CurrentAttributes
(issue #431) in their stored form — { "Current" => serialized attrs } —
or nil. Handlers normally just read Current (it is restored around
handle); the raw form is here for tests and explicit access.
11 12 13 |
# File 'lib/pgbus/event.rb', line 11 def event_id @event_id end |
#headers ⇒ Object (readonly)
context is the publisher's persisted ActiveSupport::CurrentAttributes
(issue #431) in their stored form — { "Current" => serialized attrs } —
or nil. Handlers normally just read Current (it is restored around
handle); the raw form is here for tests and explicit access.
11 12 13 |
# File 'lib/pgbus/event.rb', line 11 def headers @headers end |
#payload ⇒ Object (readonly)
context is the publisher's persisted ActiveSupport::CurrentAttributes
(issue #431) in their stored form — { "Current" => serialized attrs } —
or nil. Handlers normally just read Current (it is restored around
handle); the raw form is here for tests and explicit access.
11 12 13 |
# File 'lib/pgbus/event.rb', line 11 def payload @payload end |
#published_at ⇒ Object (readonly)
context is the publisher's persisted ActiveSupport::CurrentAttributes
(issue #431) in their stored form — { "Current" => serialized attrs } —
or nil. Handlers normally just read Current (it is restored around
handle); the raw form is here for tests and explicit access.
11 12 13 |
# File 'lib/pgbus/event.rb', line 11 def published_at @published_at end |
#routing_key ⇒ Object (readonly)
context is the publisher's persisted ActiveSupport::CurrentAttributes
(issue #431) in their stored form — { "Current" => serialized attrs } —
or nil. Handlers normally just read Current (it is restored around
handle); the raw form is here for tests and explicit access.
11 12 13 |
# File 'lib/pgbus/event.rb', line 11 def routing_key @routing_key end |
Instance Method Details
#[](key) ⇒ Object
22 23 24 |
# File 'lib/pgbus/event.rb', line 22 def [](key) payload.is_a?(Hash) ? payload[key.to_s] : nil end |
#to_h ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/pgbus/event.rb', line 26 def to_h { "event_id" => event_id, "payload" => payload, "published_at" => published_at.iso8601(6), "routing_key" => routing_key, "headers" => headers } end |