Class: Alondra::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/alondra/message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, channel_names) ⇒ Message

Returns a new instance of Message.



6
7
8
9
# File 'lib/alondra/message.rb', line 6

def initialize(content, channel_names)
  @content       = content
  @channel_names = channel_names
end

Instance Attribute Details

#channel_namesObject (readonly)

Returns the value of attribute channel_names.



4
5
6
# File 'lib/alondra/message.rb', line 4

def channel_names
  @channel_names
end

#contentObject (readonly)

Returns the value of attribute content.



3
4
5
# File 'lib/alondra/message.rb', line 3

def content
  @content
end

Instance Method Details

#as_jsonObject



21
22
23
# File 'lib/alondra/message.rb', line 21

def as_json
  {:message => content, :channel_names => channel_names}
end

#enqueueObject



11
12
13
# File 'lib/alondra/message.rb', line 11

def enqueue
  MessageQueueClient.push self
end

#send_to_channelsObject



15
16
17
18
19
# File 'lib/alondra/message.rb', line 15

def send_to_channels
  channels.each do |channel|
    channel.receive self
  end
end

#to_jsonObject



25
26
27
# File 'lib/alondra/message.rb', line 25

def to_json
  ActiveSupport::JSON.encode(as_json)
end