Class: Ably::Models::MessageEncoders::Base
- Inherits:
-
Object
- Object
- Ably::Models::MessageEncoders::Base
- Defined in:
- lib/submodules/ably-ruby/lib/ably/models/message_encoders/base.rb
Overview
Base interface for an Ably Encoder
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#add_encoding_to_message(encoding, message) ⇒ void
Add encoding to the message Hash.
-
#current_encoding_part(message) ⇒ String?
Returns the right most encoding form a meessage encoding, and nil if none exists i.e.
-
#decode(message, channel_options) ⇒ void
#decode is called once for every encoding step i.e.
-
#encode(message, channel_options) ⇒ void
#encode is called once before a message is sent to Ably.
-
#initialize(client, options = {}) ⇒ Base
constructor
A new instance of Base.
-
#is_empty?(message) ⇒ Boolean
True of the message data payload is empty.
-
#strip_current_encoding_part(message) ⇒ void
Strip the current encoding part within the message Hash.
Constructor Details
#initialize(client, options = {}) ⇒ Base
Returns a new instance of Base.
20 21 22 23 |
# File 'lib/submodules/ably-ruby/lib/ably/models/message_encoders/base.rb', line 20 def initialize(client, = {}) @client = client @options = end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
18 19 20 |
# File 'lib/submodules/ably-ruby/lib/ably/models/message_encoders/base.rb', line 18 def client @client end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
18 19 20 |
# File 'lib/submodules/ably-ruby/lib/ably/models/message_encoders/base.rb', line 18 def @options end |
Instance Method Details
#add_encoding_to_message(encoding, message) ⇒ void
This method returns an undefined value.
Add encoding to the message Hash. Ensures that encoding delimeter is used where required i.e utf-8/cipher+aes-128-cbc/base64
62 63 64 |
# File 'lib/submodules/ably-ruby/lib/ably/models/message_encoders/base.rb', line 62 def (encoding, ) [:encoding] = [[:encoding], encoding].compact.join('/') end |
#current_encoding_part(message) ⇒ String?
Returns the right most encoding form a meessage encoding, and nil if none exists i.e. current_encoding_part(‘utf-8/cipher+aes-128-cbc/base64’) => ‘base64’
70 71 72 73 74 |
# File 'lib/submodules/ably-ruby/lib/ably/models/message_encoders/base.rb', line 70 def current_encoding_part() if [:encoding] [:encoding].split('/')[-1] end end |
#decode(message, channel_options) ⇒ void
This method returns an undefined value.
#decode is called once for every encoding step i.e. if message encoding arrives with ‘utf-8/cipher+aes-128-cbc/base64’
the decoder will call #decode once for each encoding part such as 'base64', then 'cipher+aes-128-cbc', and finally 'utf-8'
It is the responsibility of the #decode method to detect the current encoding part and modify the :data & :encoding properties of the message object.
51 52 53 |
# File 'lib/submodules/ably-ruby/lib/ably/models/message_encoders/base.rb', line 51 def decode(, ) raise "Not yet implemented" end |
#encode(message, channel_options) ⇒ void
This method returns an undefined value.
#encode is called once before a message is sent to Ably
It is the responsibility of the #encode method to detect the intended encoding and modify the :data & :encoding properties of the message object.
35 36 37 |
# File 'lib/submodules/ably-ruby/lib/ably/models/message_encoders/base.rb', line 35 def encode(, ) raise "Not yet implemented" end |
#is_empty?(message) ⇒ Boolean
True of the message data payload is empty
95 96 97 |
# File 'lib/submodules/ably-ruby/lib/ably/models/message_encoders/base.rb', line 95 def is_empty?() [:data].nil? || [:data] == '' end |
#strip_current_encoding_part(message) ⇒ void
This method returns an undefined value.
Strip the current encoding part within the message Hash.
For example, calling this method on an :encoding value of ‘utf-8/cipher+aes-128-cbc/base64’ would update the attribute :encoding to ‘utf-8/cipher+aes-128-cbc’
84 85 86 87 88 |
# File 'lib/submodules/ably-ruby/lib/ably/models/message_encoders/base.rb', line 84 def strip_current_encoding_part() raise "Cannot strip encoding when there is no encoding for this message" unless [:encoding] [:encoding] = [:encoding].split('/')[0...-1].join('/') [:encoding] = nil if [:encoding].empty? end |