lib/submodules/ably-ruby/lib/ably/models/message.rb in ably-rest-0.8.6 vs lib/submodules/ably-ruby/lib/ably/models/message.rb in ably-rest-0.8.9
- old
+ new
@@ -32,66 +32,66 @@
# @return [Time] Timestamp when the message was received by the Ably the realtime service
# @!attribute [r] id
# @return [String] A globally unique message ID
# @!attribute [r] connection_id
# @return [String] The connection_id of the publisher of the message
- # @!attribute [r] hash
+ # @!attribute [r] attributes
# @return [Hash] Access the protocol message Hash object ruby'fied to use symbolized keys
#
class Message
include Ably::Modules::Conversions
include Ably::Modules::Encodeable
include Ably::Modules::ModelCommon
include Ably::Modules::SafeDeferrable if defined?(Ably::Realtime)
# {Message} initializer
#
- # @param hash_object [Hash] object with the underlying message details
+ # @param attributes [Hash] object with the underlying message detail key value attributes
# @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, options = {})
+ def initialize(attributes, options = {})
@logger = options[:logger] # Logger expected for SafeDeferrable
@protocol_message = options[:protocol_message]
- @raw_hash_object = hash_object
+ @raw_hash_object = attributes
- set_hash_object hash_object
+ set_attributes_object attributes
ensure_utf_8 :name, name, allow_nil: true
ensure_utf_8 :client_id, client_id, allow_nil: true
ensure_utf_8 :encoding, encoding, allow_nil: true
end
- %w( name client_id encoding connection_id ).each do |attribute|
+ %w( name client_id encoding ).each do |attribute|
define_method attribute do
- hash[attribute.to_sym]
+ attributes[attribute.to_sym]
end
end
def data
- @data ||= hash[:data].freeze
+ @data ||= attributes[:data].freeze
end
def id
- hash.fetch(:id) { "#{protocol_message.id!}:#{protocol_message_index}" }
+ attributes.fetch(:id) { "#{protocol_message.id!}:#{protocol_message_index}" }
end
def connection_id
- hash.fetch(:connection_id) { protocol_message.connection_id if assigned_to_protocol_message? }
+ attributes.fetch(:connection_id) { protocol_message.connection_id if assigned_to_protocol_message? }
end
def timestamp
- if hash[:timestamp]
- as_time_from_epoch(hash[:timestamp])
+ if attributes[:timestamp]
+ as_time_from_epoch(attributes[:timestamp])
else
protocol_message.timestamp
end
end
- def hash
- @hash_object
+ def attributes
+ @attributes
end
def to_json(*args)
as_json(*args).tap do |message|
decode_binary_data_before_to_json message
@@ -118,17 +118,19 @@
raise RuntimeError, 'Message is not yet published with a ProtocolMessage. ProtocolMessage is nil' if @protocol_message.nil?
@protocol_message
end
private
- attr_reader :raw_hash_object
+ def raw_hash_object
+ @raw_hash_object
+ end
def protocol_message_index
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])
+ def set_attributes_object(new_attributes)
+ @attributes = IdiomaticRubyWrapper(new_attributes.clone.freeze, stop_at: [:data])
end
def logger
return @logger if @logger
protocol_message.logger if protocol_message