class Warren::Message::Short

Light-weight interim message which can be expanded to a full payload later.

Attributes

record[R]

Public Class Methods

new(record = nil, class_name: nil, id: nil) click to toggle source

Create a 'short' message, where the payload is just the class name and id. Designed for when you wish to use a delayed broadcast.

@param record [ActiveRecord::Base] An Active Record object

# File lib/warren/message/short.rb, line 21
def initialize(record = nil, class_name: nil, id: nil)
  if record
    @class_name = record.class.name
    @id = record.id
  else
    @class_name = class_name
    @id = id
  end
end

Public Instance Methods

headers() click to toggle source

For compatibility. Returns an empty hash.

@return [{}] Empty hash

# File lib/warren/message/short.rb, line 62
def headers
  {}
end
payload() click to toggle source

The contents of the message, a string in the form:

“<ClassName>”,<id>

@return [String] The payload of the message

# File lib/warren/message/short.rb, line 54
def payload
  [@class_name, @id].to_json
end
queue(warren) click to toggle source

Queues the message for broadcast at the end of the transaction. Actually want to make this the default behaviour, but only realised the need when doing some last minute integration tests. Will revisit this in the next version. (Or possibly post code review depending)

# File lib/warren/message/short.rb, line 34
def queue(warren)
  after_commit { warren << self }
rescue NoMethodError
  raise StandardError, '#queue depends on the after_commit_everywhere gem. Please add this to your gemfile'
end
routing_key() click to toggle source

The routing key for the message.

@return [String] The routing key

# File lib/warren/message/short.rb, line 44
def routing_key
  "queue_broadcast.#{@class_name.underscore}.#{@id}"
end