Class: Warren::QueueBroadcastMessage

Inherits:
Object
  • Object
show all
Includes:
AfterCommitEverywhere
Defined in:
lib/warren/queue_broadcast_message.rb

Overview

rubocop:todo Style/Documentation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record = nil, class_name: nil, id: nil) ⇒ QueueBroadcastMessage

Returns a new instance of QueueBroadcastMessage.


6
7
8
9
10
11
12
13
14
15
# File 'lib/warren/queue_broadcast_message.rb', line 6

def initialize(record = nil, class_name: nil, id: nil)
  if record
    @record = record
    @class_name = record.class.name
    @id = record.id
  else
    @class_name = class_name
    @id = id
  end
end

Instance Attribute Details

#recordObject (readonly)

Returns the value of attribute record


4
5
6
# File 'lib/warren/queue_broadcast_message.rb', line 4

def record
  @record
end

Instance Method Details

#payloadObject


25
26
27
# File 'lib/warren/queue_broadcast_message.rb', line 25

def payload
  [@class_name, @id].to_json
end

#queue(warren) ⇒ Object


17
18
19
# File 'lib/warren/queue_broadcast_message.rb', line 17

def queue(warren)
  after_commit { warren << self }
end

#routing_keyObject


21
22
23
# File 'lib/warren/queue_broadcast_message.rb', line 21

def routing_key
  "#{Rails.env}.queue_broadcast.#{@class_name.underscore}.#{@id}"
end