lib/ably/models/protocol_message.rb in ably-0.1.6 vs lib/ably/models/protocol_message.rb in ably-0.2.0
- old
+ new
@@ -31,10 +31,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
extend Ably::Modules::Enum
# Actions which are sent by the Ably Realtime API
#
# The values correspond to the ints which the API
@@ -65,11 +66,11 @@
def initialize(hash_object)
@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?
+ 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)
@hash_object.freeze
end
@@ -78,11 +79,11 @@
hash[attribute.to_sym]
end
end
def id!
- raise RuntimeError, "ProtocolMessage #id is nil" unless id
+ raise RuntimeError, 'ProtocolMessage #id is nil' unless id
id
end
def action
ACTION(hash[:action])
@@ -166,11 +167,11 @@
@hash_object
end
# Return a JSON ready object from the underlying #hash using Ably naming conventions for keys
def as_json(*args)
- raise TypeError, ":action is missing, cannot generate a valid Hash for ProtocolMessage" unless action
- raise TypeError, ":msg_serial or :connection_serial is missing, cannot generate a valid Hash for ProtocolMessage" if ack_required? && !has_serial?
+ raise TypeError, ':action is missing, cannot generate a valid Hash for ProtocolMessage' unless action
+ raise TypeError, ':msg_serial or :connection_serial is missing, cannot generate a valid Hash for ProtocolMessage' if ack_required? && !has_serial?
hash.dup.tap do |hash_object|
hash_object['action'] = action.to_i
hash_object['messages'] = messages.map(&:as_json) unless messages.empty?
hash_object['presence'] = presence.map(&:as_json) unless presence.empty?