lib/submodules/ably-ruby/lib/ably/models/message.rb in ably-rest-0.7.3 vs lib/submodules/ably-ruby/lib/ably/models/message.rb in ably-rest-0.7.5
- old
+ new
@@ -1,20 +1,20 @@
module Ably::Models
# Convert messsage argument to a {Message} object and associate with a protocol message if provided
#
# @param message [Message,Hash] A message object or Hash of message properties
- # @param protocol_message [ProtocolMessage] An optional protocol message to assocate the message with
+ # @param [Hash] options (see Message#initialize)
#
# @return [Message]
- def self.Message(message, protocol_message = nil)
+ def self.Message(message, options = {})
case message
when Message
message.tap do
- message.assign_to_protocol_message protocol_message
+ message.assign_to_protocol_message options[:protocol_message] if options[:protocol_message]
end
else
- Message.new(message, protocol_message)
+ Message.new(message, options)
end
end
# A class representing an individual message to be sent or received
# via the Ably Realtime service.
@@ -39,19 +39,22 @@
#
class Message
include Ably::Modules::Conversions
include Ably::Modules::Encodeable
include Ably::Modules::ModelCommon
- include EventMachine::Deferrable
+ include Ably::Modules::SafeDeferrable if defined?(Ably::Realtime)
# {Message} initializer
#
- # @param hash_object [Hash] object with the underlying message details
- # @param protocol_message [ProtocolMessage] if this message has been published, then it is associated with a {ProtocolMessage}
+ # @param hash_object [Hash] object with the underlying message details
+ # @param [Hash] options an options Hash for this initializer
+ # @option options [ProtocolMessage] :protocol_message An optional protocol message to assocate the presence message with
+ # @option options [Logger] :logger An optional Logger to be used by {Ably::Modules::SafeDeferrable} if an exception is caught in a callback
#
- def initialize(hash_object, protocol_message = nil)
- @protocol_message = protocol_message
+ def initialize(hash_object, options = {})
+ @logger = options[:logger] # Logger expected for SafeDeferrable
+ @protocol_message = options[:protocol_message]
@raw_hash_object = hash_object
set_hash_object hash_object
ensure_utf_8 :name, name, allow_nil: true
@@ -125,8 +128,13 @@
protocol_message.messages.map(&:object_id).index(self.object_id)
end
def set_hash_object(hash)
@hash_object = IdiomaticRubyWrapper(hash.clone.freeze, stop_at: [:data])
+ end
+
+ def logger
+ return logger if logger
+ protocol_message.logger if protocol_message
end
end
end