Module: Ably::Modules::ModelCommon
- Includes:
- Conversions, MessagePack
- Included in:
- Ably::Models::ChannelStateChange, Ably::Models::CipherParams, Ably::Models::ConnectionDetails, Ably::Models::ConnectionStateChange, Ably::Models::ErrorInfo, Ably::Models::Message, Ably::Models::PresenceMessage, Ably::Models::ProtocolMessage, Ably::Models::Stats, Ably::Models::TokenDetails, Ably::Models::TokenRequest
- Defined in:
- lib/ably/modules/model_common.rb
Overview
Common model functionality shared across many Ably::Models
Instance Attribute Summary collapse
-
#hash ⇒ Integer
readonly
Compute a hash-code for this hash.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#[](key) ⇒ Object
Provide a normal Hash accessor to the underlying raw message object.
-
#as_json ⇒ Hash
Return a JSON ready object from the underlying #attributes using Ably naming conventions for keys.
-
#to_json(*args) ⇒ String
Stringify the JSON representation of this object from the underlying #attributes.
Methods included from MessagePack
Instance Attribute Details
#hash ⇒ Integer (readonly)
Returns Compute a hash-code for this hash. Two hashes with the same content will have the same hash code.
37 38 39 |
# File 'lib/ably/modules/model_common.rb', line 37 def hash attributes.hash end |
Instance Method Details
#==(other) ⇒ Object
18 19 20 21 |
# File 'lib/ably/modules/model_common.rb', line 18 def ==(other) other.kind_of?(self.class) && attributes == other.attributes end |
#[](key) ⇒ Object
Provide a normal Hash accessor to the underlying raw message object
14 15 16 |
# File 'lib/ably/modules/model_common.rb', line 14 def [](key) attributes[key] end |
#as_json ⇒ Hash
Return a JSON ready object from the underlying #attributes using Ably naming conventions for keys
25 26 27 |
# File 'lib/ably/modules/model_common.rb', line 25 def as_json attributes.as_json.reject { |key, val| val.nil? } end |
#to_json(*args) ⇒ String
Stringify the JSON representation of this object from the underlying #attributes
31 32 33 |
# File 'lib/ably/modules/model_common.rb', line 31 def to_json(*args) as_json.to_json(*args) end |