Class: EventPeople::Event
- Inherits:
-
Object
- Object
- EventPeople::Event
- Defined in:
- lib/event_people/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
- #body? ⇒ Boolean
-
#initialize(name, body, schema_version = 1.0) ⇒ Event
constructor
A new instance of Event.
- #name? ⇒ Boolean
- #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 12 13 14 15 16 |
# File 'lib/event_people/event.rb', line 5 def initialize(name, body, schema_version = 1.0) @name = name @body = body.is_a?(String) ? JSON.parse(body) : body @schema_version = @body&.dig('headers', 'schemaVersion') || schema_version if name? generate_headers fix_name end build_payload if @body&.key?('headers') end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
3 4 5 |
# File 'lib/event_people/event.rb', line 3 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
3 4 5 |
# File 'lib/event_people/event.rb', line 3 def headers @headers end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/event_people/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_people/event.rb', line 3 def schema_version @schema_version end |
Instance Method Details
#body? ⇒ Boolean
22 23 24 |
# File 'lib/event_people/event.rb', line 22 def body? body && !body.empty? end |
#name? ⇒ Boolean
26 27 28 |
# File 'lib/event_people/event.rb', line 26 def name? name && !name.empty? end |
#payload ⇒ Object
18 19 20 |
# File 'lib/event_people/event.rb', line 18 def payload { headers: headers, body: body }.to_json end |