Class: Megaphone::Client::Event
- Inherits:
-
Object
- Object
- Megaphone::Client::Event
- Defined in:
- lib/megaphone/client/event.rb
Instance Method Summary collapse
- #errors ⇒ Object
-
#initialize(topic, subtopic, origin, schema, partition_key, payload) ⇒ Event
constructor
A new instance of Event.
- #stream_id ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(topic, subtopic, origin, schema, partition_key, payload) ⇒ Event
Returns a new instance of Event.
6 7 8 9 10 11 12 13 |
# File 'lib/megaphone/client/event.rb', line 6 def initialize(topic, subtopic, origin, schema, partition_key, payload) @topic = topic @subtopic = subtopic @origin = origin @schema = schema @partition_key = partition_key @payload = payload end |
Instance Method Details
#errors ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/megaphone/client/event.rb', line 34 def errors errors = [] errors << 'partition_key must not be empty' if missing?(@partition_key) errors << 'topic must not be empty' if missing?(@topic) errors << 'subtopic must not be empty' if missing?(@subtopic) errors << 'payload must not be empty' if missing?(@payload) errors << 'origin must not be empty' if missing?(@origin) errors end |
#stream_id ⇒ Object
15 16 17 |
# File 'lib/megaphone/client/event.rb', line 15 def stream_id "#{@topic}.#{@subtopic}" end |
#to_hash ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/megaphone/client/event.rb', line 19 def to_hash { schema: @schema, origin: @origin, topic: @topic, subtopic: @subtopic, partitionKey: @partition_key, data: @payload } end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/megaphone/client/event.rb', line 30 def to_s JSON.dump(to_hash) end |
#valid? ⇒ Boolean
44 45 46 |
# File 'lib/megaphone/client/event.rb', line 44 def valid? errors.empty? end |