lib/submodules/ably-ruby/lib/ably/models/presence_message.rb in ably-rest-0.9.3 vs lib/submodules/ably-ruby/lib/ably/models/presence_message.rb in ably-rest-1.0.0
- old
+ new
@@ -121,11 +121,10 @@
as_json(*args).tap do |presence_message|
decode_binary_data_before_to_json presence_message
end.to_json
end
-
# Assign this presence message to a ProtocolMessage before delivery to the Ably system
# @api private
def assign_to_protocol_message(protocol_message)
@protocol_message = protocol_message
end
@@ -141,9 +140,22 @@
# @return [Ably::Models::ProtocolMessage]
# @api private
def protocol_message
raise RuntimeError, 'Presence Message is not yet published with a ProtocolMessage. ProtocolMessage is nil' if @protocol_message.nil?
@protocol_message
+ end
+
+ # Create a static shallow clone of this object with the optional attributes to overide existing values
+ # Shallow clones have no dependency on the originating ProtocolMessage as all field values are stored as opposed to calculated
+ # Clones are useful when the original PresenceMessage needs to be mutated, such as storing in a PresenceMap with action :present
+ def shallow_clone(new_attributes = {})
+ new_attributes = IdiomaticRubyWrapper(new_attributes.clone.freeze, stop_at: [:data])
+
+ self.class.new(attributes.to_hash.merge(
+ id: new_attributes[:id] || id,
+ connection_id: new_attributes[:connection_id] || connection_id,
+ timestamp: new_attributes[:timestamp] || as_since_epoch(timestamp)
+ ).merge(new_attributes.to_hash))
end
private
def raw_hash_object
@raw_hash_object