Class: MessageBus::Message
- Inherits:
-
Object
- Object
- 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
- #==(other) ⇒ Object
-
#encode ⇒ Object
only tricky thing to encode is pipes in a channel name ...
- #encode_without_ids ⇒ Object
-
#initialize(global_id, message_id, channel, data) ⇒ Message
constructor
A new instance of Message.
Constructor Details
#initialize(global_id, message_id, channel, data) ⇒ Message
Returns a new instance of Message.
8 9 10 11 12 13 |
# File 'lib/message_bus/message.rb', line 8 def initialize(global_id, , channel, data) @global_id = global_id @message_id = @channel = channel @data = data end |
Instance Attribute Details
#channel ⇒ Object
Returns the value of attribute channel.
5 6 7 |
# File 'lib/message_bus/message.rb', line 5 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.
5 6 7 |
# File 'lib/message_bus/message.rb', line 5 def data @data end |
#global_id ⇒ Object
Returns the value of attribute global_id.
5 6 7 |
# File 'lib/message_bus/message.rb', line 5 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.
5 6 7 |
# File 'lib/message_bus/message.rb', line 5 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
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/message_bus/message.rb', line 15 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] new(global_id, , channel, data) end |
Instance Method Details
#==(other) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/message_bus/message.rb', line 38 def ==(other) other.is_a?(self.class) && self.global_id == other.global_id && self. == other. && self.channel == other.channel && self.data == other.data end |
#encode ⇒ Object
only tricky thing to encode is pipes in a channel name ... do a straight replace
30 31 32 |
# File 'lib/message_bus/message.rb', line 30 def encode "#{global_id}|#{}|#{channel.gsub("|", "$$123$$")}|#{data}" end |
#encode_without_ids ⇒ Object
34 35 36 |
# File 'lib/message_bus/message.rb', line 34 def encode_without_ids "#{channel.gsub("|", "$$123$$")}|#{data}" end |