class Megaphone::Client::Event
Public Class Methods
new(topic, subtopic, origin, schema, partition_key, payload)
click to toggle source
# 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
Public Instance Methods
errors()
click to toggle source
# 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()
click to toggle source
# File lib/megaphone/client/event.rb, line 15 def stream_id "#{@topic}.#{@subtopic}" end
to_hash()
click to toggle source
# 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()
click to toggle source
# File lib/megaphone/client/event.rb, line 30 def to_s JSON.dump(to_hash) end
valid?()
click to toggle source
# File lib/megaphone/client/event.rb, line 44 def valid? errors.empty? end
Private Instance Methods
missing?(field)
click to toggle source
# File lib/megaphone/client/event.rb, line 50 def missing?(field) not (field && field.to_s.length > 0) end