Class: MessageBus::Message
- Inherits:
-
Struct
- Object
- Struct
- MessageBus::Message
- Defined in:
- lib/message_bus/message.rb
Overview
Represents a published message and its encoding for persistence.
Instance Attribute Summary collapse
-
#channel ⇒ Object
Returns the value of attribute channel.
-
#client_ids ⇒ Object
Returns the value of attribute client_ids.
-
#data ⇒ Object
Returns the value of attribute data.
-
#global_id ⇒ Object
Returns the value of attribute global_id.
-
#group_ids ⇒ Object
Returns the value of attribute group_ids.
-
#message_id ⇒ Object
Returns the value of attribute message_id.
-
#site_id ⇒ Object
Returns the value of attribute site_id.
-
#user_ids ⇒ Object
Returns the value of attribute user_ids.
Class Method Summary collapse
Instance Method Summary collapse
-
#encode ⇒ Object
only tricky thing to encode is pipes in a channel name …
- #encode_without_ids ⇒ Object
Instance Attribute Details
#channel ⇒ Object
Returns the value of attribute channel
4 5 6 |
# File 'lib/message_bus/message.rb', line 4 def channel @channel end |
#client_ids ⇒ Object
Returns the value of attribute client_ids.
5 6 7 |
# File 'lib/message_bus/message.rb', line 5 def client_ids @client_ids end |
#data ⇒ Object
Returns the value of attribute data
4 5 6 |
# File 'lib/message_bus/message.rb', line 4 def data @data end |
#global_id ⇒ Object
Returns the value of attribute global_id
4 5 6 |
# File 'lib/message_bus/message.rb', line 4 def global_id @global_id end |
#group_ids ⇒ Object
Returns the value of attribute group_ids.
5 6 7 |
# File 'lib/message_bus/message.rb', line 5 def group_ids @group_ids end |
#message_id ⇒ Object
Returns the value of attribute message_id
4 5 6 |
# File 'lib/message_bus/message.rb', line 4 def @message_id end |
#site_id ⇒ Object
Returns the value of attribute site_id.
5 6 7 |
# File 'lib/message_bus/message.rb', line 5 def site_id @site_id end |
#user_ids ⇒ Object
Returns the value of attribute user_ids.
5 6 7 |
# File 'lib/message_bus/message.rb', line 5 def user_ids @user_ids end |
Class Method Details
.decode(encoded) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/message_bus/message.rb', line 7 def self.decode(encoded) s1 = encoded.index("|") s2 = encoded.index("|", s1 + 1) s3 = encoded.index("|", s2 + 1) global_id = encoded[0, s1 + 1].to_i = encoded[(s1 + 1), (s2 - s1 - 1)].to_i channel = encoded[(s2 + 1), (s3 - s2 - 1)] channel.gsub!("$$123$$", "|") data = encoded[(s3 + 1), encoded.size] MessageBus::Message.new(global_id, , channel, data) end |
Instance Method Details
#encode ⇒ Object
only tricky thing to encode is pipes in a channel name … do a straight replace
22 23 24 |
# File 'lib/message_bus/message.rb', line 22 def encode "#{global_id}|#{}|#{channel.gsub("|", "$$123$$")}|#{data}" end |
#encode_without_ids ⇒ Object
26 27 28 |
# File 'lib/message_bus/message.rb', line 26 def encode_without_ids "#{channel.gsub("|", "$$123$$")}|#{data}" end |