Module: Ably::Modules::Encodeable::ClassMethods

Defined in:
lib/ably/modules/encodeable.rb

Instance Method Summary collapse

Instance Method Details

#from_encoded(message_object, channel_options = {}) {|Ably::Exceptions::BaseAblyException| ... } ⇒ Message, Presence

Return a Message or Presence object from the encoded JSON-like object, using the optional channel options

Parameters:

  • message_object (Hash)

    JSON-like object representation of an encoded message

  • channel_options (Hash) (defaults to: {})

    Channel options, currently reserved for Encryption options

Yields:

Returns:

  • (Message, Presence)


23
24
25
26
27
# File 'lib/ably/modules/encodeable.rb', line 23

def from_encoded(message_object, channel_options = {}, &error_block)
  new(message_object).tap do |message|
    message.decode(encoders, channel_options, &error_block)
  end
end

#from_encoded_array(message_object_array, channel_options = {}) ⇒ Array<Message,Presence>

Return an Array of Message or Presence objects from the encoded Array of JSON-like objects, using the optional channel options

Parameters:

  • message_object_array (Array<Hash>)

    Array of JSON-like objects with encoded messages

  • channel_options (Hash) (defaults to: {})

    Channel options, currently reserved for Encryption options

Returns:

  • (Array<Message,Presence>)


33
34
35
36
37
# File 'lib/ably/modules/encodeable.rb', line 33

def from_encoded_array(message_object_array, channel_options = {})
  Array(message_object_array).map do |message_object|
    from_encoded(message_object, channel_options)
  end
end

#register_encoder(encoder, options = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Register an encoder for this object



41
42
43
# File 'lib/ably/modules/encodeable.rb', line 41

def register_encoder(encoder, options = {})
  encoders << Ably::Models::MessageEncoders.encoder_from(encoder, options)
end