Module: Ably::Modules::ModelCommon
- Includes:
- Conversions, MessagePack
- Included in:
- Ably::Models::AuthDetails, Ably::Models::ChannelDetails, Ably::Models::ChannelMetrics, Ably::Models::ChannelOccupancy, Ably::Models::ChannelOptions, Ably::Models::ChannelStateChange, Ably::Models::ChannelStatus, Ably::Models::CipherParams, Ably::Models::ConnectionDetails, Ably::Models::ConnectionStateChange, Ably::Models::DeltaExtras, Ably::Models::DeviceDetails, Ably::Models::DevicePushDetails, Ably::Models::ErrorInfo, Ably::Models::Message, Ably::Models::PresenceMessage, Ably::Models::ProtocolMessage, Ably::Models::PushChannelSubscription, Ably::Models::Stats, Ably::Models::TokenDetails, Ably::Models::TokenRequest
- Defined in:
- lib/submodules/ably-ruby/lib/ably/modules/model_common.rb
Overview
Common model functionality shared across many Ably::Models
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#hash ⇒ Integer
readonly
Compute a hash-code for this hash.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#[](key) ⇒ Object
Provide a normal Hash accessor to the underlying raw message object.
-
#as_json(*args) ⇒ 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.
- #to_s ⇒ Object
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.
46 47 48 |
# File 'lib/submodules/ably-ruby/lib/ably/modules/model_common.rb', line 46 def hash attributes.hash end |
Class Method Details
.included(base) ⇒ Object
11 12 13 |
# File 'lib/submodules/ably-ruby/lib/ably/modules/model_common.rb', line 11 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#==(other) ⇒ Object
23 24 25 26 |
# File 'lib/submodules/ably-ruby/lib/ably/modules/model_common.rb', line 23 def ==(other) other.kind_of?(self.class) && attributes == other.attributes end |
#[](key) ⇒ Object
Provide a normal Hash accessor to the underlying raw message object
19 20 21 |
# File 'lib/submodules/ably-ruby/lib/ably/modules/model_common.rb', line 19 def [](key) attributes[key] end |
#as_json(*args) ⇒ Hash
Return a JSON ready object from the underlying #attributes using Ably naming conventions for keys
32 33 34 |
# File 'lib/submodules/ably-ruby/lib/ably/modules/model_common.rb', line 32 def as_json(*args) attributes.as_json.reject { |key, val| val.nil? } end |
#to_json(*args) ⇒ String
Stringify the JSON representation of this object from the underlying #attributes
40 41 42 |
# File 'lib/submodules/ably-ruby/lib/ably/modules/model_common.rb', line 40 def to_json(*args) as_json.to_json(*args) end |
#to_s ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/submodules/ably-ruby/lib/ably/modules/model_common.rb', line 50 def to_s representation = attributes.map do |key, val| if val.nil? nil else val_str = val.to_s val_str = "#{val_str[0...80]}..." if val_str.length > 80 "#{key}=#{val_str}" end end "<#{self.class.name}: #{representation.compact.join(', ')}>" end |