Class: Pgbus::Event
- Inherits:
-
Object
- Object
- Pgbus::Event
- Defined in:
- lib/pgbus/event.rb
Instance Attribute Summary collapse
-
#event_id ⇒ Object
readonly
Returns the value of attribute event_id.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#published_at ⇒ Object
readonly
Returns the value of attribute published_at.
-
#routing_key ⇒ Object
readonly
Returns the value of attribute routing_key.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(event_id:, payload:, published_at: nil, routing_key: nil, headers: 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) ⇒ Event
Returns a new instance of Event.
9 10 11 12 13 14 15 |
# File 'lib/pgbus/event.rb', line 9 def initialize(event_id:, payload:, published_at: nil, routing_key: nil, headers: nil) @event_id = event_id @payload = payload @published_at = published_at || Time.now.utc @routing_key = routing_key @headers = headers || {} end |
Instance Attribute Details
#event_id ⇒ Object (readonly)
Returns the value of attribute event_id.
7 8 9 |
# File 'lib/pgbus/event.rb', line 7 def event_id @event_id end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
7 8 9 |
# File 'lib/pgbus/event.rb', line 7 def headers @headers end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
7 8 9 |
# File 'lib/pgbus/event.rb', line 7 def payload @payload end |
#published_at ⇒ Object (readonly)
Returns the value of attribute published_at.
7 8 9 |
# File 'lib/pgbus/event.rb', line 7 def published_at @published_at end |
#routing_key ⇒ Object (readonly)
Returns the value of attribute routing_key.
7 8 9 |
# File 'lib/pgbus/event.rb', line 7 def routing_key @routing_key end |
Instance Method Details
#[](key) ⇒ Object
17 18 19 |
# File 'lib/pgbus/event.rb', line 17 def [](key) payload.is_a?(Hash) ? payload[key.to_s] : nil end |
#to_h ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/pgbus/event.rb', line 21 def to_h { "event_id" => event_id, "payload" => payload, "published_at" => published_at.iso8601(6), "routing_key" => routing_key, "headers" => headers } end |