lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb in ably-rest-0.7.3 vs lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb in ably-rest-0.7.5

- old
+ new

@@ -35,11 +35,11 @@ # @!attribute [r] hash # @return [Hash] Access the protocol message Hash object ruby'fied to use symbolized keys # class ProtocolMessage include Ably::Modules::ModelCommon - include EventMachine::Deferrable if defined?(Ably::Realtime) + include Ably::Modules::SafeDeferrable if defined?(Ably::Realtime) extend Ably::Modules::Enum # Actions which are sent by the Ably Realtime API # # The values correspond to the ints which the API @@ -67,11 +67,19 @@ # Indicates this protocol message action will generate an ACK response such as :message or :presence def self.ack_required?(for_action) [ACTION.Presence, ACTION.Message].include?(ACTION(for_action)) end - def initialize(hash_object) + # {ProtocolMessage} initializer + # + # @param hash_object [Hash] object with the underlying protocol message data + # @param [Hash] options an options Hash for this initializer + # @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, options = {}) + @logger = options[:logger] # Logger expected for SafeDeferrable + @raw_hash_object = hash_object @hash_object = IdiomaticRubyWrapper(@raw_hash_object.clone) raise ArgumentError, 'Invalid ProtocolMessage, action cannot be nil' if @hash_object[:action].nil? @hash_object[:action] = ACTION(@hash_object[:action]).to_i unless @hash_object[:action].kind_of?(Integer) @@ -145,22 +153,22 @@ end def messages @messages ||= Array(hash[:messages]).map do |message| - Ably::Models.Message(message, self) + Ably::Models.Message(message, protocol_message: self) end end def add_message(message) messages << message end def presence @presence ||= Array(hash[:presence]).map do |message| - Ably::Models.PresenceMessage(message, self) + Ably::Models.PresenceMessage(message, protocol_message: self) end end # Flags as bits def flags @@ -204,7 +212,10 @@ # @api private def invalid? action_enum = action rescue nil !action_enum || (ack_required? && !has_serial?) end + + private + attr_reader :logger end end