class Pwwka::PublishOptions

Encaspulates the options we pass to ‘topic_exchange.publish` as well as the various defaults and auto-generated values.

Public Class Methods

new(routing_key: , message_id: :auto_generate, type: , headers:, expiration: nil) click to toggle source
# File lib/pwwka/publish_options.rb, line 6
def initialize(routing_key: ,
               message_id: :auto_generate,
               type: ,
               headers:,
               expiration: nil)
  @options_hash = {
    routing_key: routing_key,
    message_id: message_id.to_s == "auto_generate" ? SecureRandom.uuid : message_id,
    content_type: "application/json; version=1",
    persistent:  true,
    app_id: Pwwka.configuration.app_id
  }
  @options_hash[:type]       = type unless type.nil?
  @options_hash[:headers]    = headers unless headers.nil?
  @options_hash[:expiration] = expiration unless expiration.nil?
end

Public Instance Methods

message_id() click to toggle source
# File lib/pwwka/publish_options.rb, line 23
def message_id
  @options_hash[:message_id]
end
to_h() click to toggle source
# File lib/pwwka/publish_options.rb, line 26
def to_h
  @options_hash.merge(timestamp: Time.now.to_i)
end