Class: Alondra::Message
- Inherits:
-
Object
- Object
- Alondra::Message
- Defined in:
- lib/alondra/message.rb
Instance Attribute Summary collapse
-
#channel_names ⇒ Object
readonly
Returns the value of attribute channel_names.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
Instance Method Summary collapse
- #as_json ⇒ Object
- #enqueue ⇒ Object
-
#initialize(content, channel_names) ⇒ Message
constructor
A new instance of Message.
- #send_to_channels ⇒ Object
- #to_json ⇒ Object
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_names ⇒ Object (readonly)
Returns the value of attribute channel_names.
4 5 6 |
# File 'lib/alondra/message.rb', line 4 def channel_names @channel_names end |
#content ⇒ Object (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_json ⇒ Object
21 22 23 |
# File 'lib/alondra/message.rb', line 21 def as_json {:message => content, :channel_names => channel_names} end |
#enqueue ⇒ Object
11 12 13 |
# File 'lib/alondra/message.rb', line 11 def enqueue MessageQueueClient.push self end |
#send_to_channels ⇒ Object
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_json ⇒ Object
25 26 27 |
# File 'lib/alondra/message.rb', line 25 def to_json ActiveSupport::JSON.encode(as_json) end |