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.
-
#retry_count ⇒ Object
readonly
Returns the value of attribute retry_count.
-
#schema_version ⇒ Object
readonly
Returns the value of attribute schema_version.
Instance Method Summary collapse
- #body? ⇒ Boolean
- #increment_retry_count ⇒ Object
-
#initialize(name, body, schema_version = 1.0, retry_count: 0) ⇒ Event
constructor
A new instance of Event.
- #name? ⇒ Boolean
- #payload ⇒ Object
Constructor Details
#initialize(name, body, schema_version = 1.0, retry_count: 0) ⇒ Event
Returns a new instance of Event.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/event_people/event.rb', line 5 def initialize(name, body, schema_version = 1.0, retry_count: 0) @name = name @body = body.is_a?(String) ? JSON.parse(body) : body @schema_version = @body&.dig('headers', 'schemaVersion') || schema_version @retry_count = retry_count.to_i 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 |
#retry_count ⇒ Object (readonly)
Returns the value of attribute retry_count.
3 4 5 |
# File 'lib/event_people/event.rb', line 3 def retry_count @retry_count 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
27 28 29 |
# File 'lib/event_people/event.rb', line 27 def body? body && !body.empty? end |
#increment_retry_count ⇒ Object
19 20 21 |
# File 'lib/event_people/event.rb', line 19 def increment_retry_count @retry_count += 1 end |
#name? ⇒ Boolean
31 32 33 |
# File 'lib/event_people/event.rb', line 31 def name? name && !name.empty? end |
#payload ⇒ Object
23 24 25 |
# File 'lib/event_people/event.rb', line 23 def payload { headers: headers, body: body }.to_json end |