Class: EventBus::Event
- Inherits:
-
Object
- Object
- EventBus::Event
- Defined in:
- lib/event_bus/event.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#schema_version ⇒ Object
readonly
Returns the value of attribute schema_version.
Instance Method Summary collapse
- #has_body? ⇒ Boolean
- #has_name? ⇒ Boolean
-
#initialize(name, body, schema_version = 1.0) ⇒ Event
constructor
A new instance of Event.
- #payload ⇒ Object
Constructor Details
#initialize(name, body, schema_version = 1.0) ⇒ Event
Returns a new instance of Event.
5 6 7 8 9 10 11 |
# File 'lib/event_bus/event.rb', line 5 def initialize(name, body, schema_version = 1.0) @name = name @body = JSON.parse(body) rescue body @schema_version = @body['headers']['schemaVersion'] rescue schema_version generate_headers if has_name? build_payload if @body && @body.has_key?('headers') end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
3 4 5 |
# File 'lib/event_bus/event.rb', line 3 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
3 4 5 |
# File 'lib/event_bus/event.rb', line 3 def headers @headers end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/event_bus/event.rb', line 3 def name @name end |
#schema_version ⇒ Object (readonly)
Returns the value of attribute schema_version.
3 4 5 |
# File 'lib/event_bus/event.rb', line 3 def schema_version @schema_version end |
Instance Method Details
#has_body? ⇒ Boolean
20 21 22 |
# File 'lib/event_bus/event.rb', line 20 def has_body? body && !body.empty? end |
#has_name? ⇒ Boolean
24 25 26 |
# File 'lib/event_bus/event.rb', line 24 def has_name? name && !name.empty? end |
#payload ⇒ Object
13 14 15 16 17 18 |
# File 'lib/event_bus/event.rb', line 13 def payload { headers: headers, body: body }.to_json end |