Module: Ably::Modules::ModelCommon
- Includes:
- Conversions, MessagePack
- Included in:
- Ably::Models::AuthDetails, Ably::Models::ChannelStateChange, 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.
41 42 43 |
# File 'lib/submodules/ably-ruby/lib/ably/modules/model_common.rb', line 41 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
22 23 24 25 |
# File 'lib/submodules/ably-ruby/lib/ably/modules/model_common.rb', line 22 def ==(other) other.kind_of?(self.class) && attributes == other.attributes end |
#[](key) ⇒ Object
Provide a normal Hash accessor to the underlying raw message object
18 19 20 |
# File 'lib/submodules/ably-ruby/lib/ably/modules/model_common.rb', line 18 def [](key) attributes[key] end |
#as_json(*args) ⇒ Hash
Return a JSON ready object from the underlying #attributes using Ably naming conventions for keys
29 30 31 |
# File 'lib/submodules/ably-ruby/lib/ably/modules/model_common.rb', line 29 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
35 36 37 |
# File 'lib/submodules/ably-ruby/lib/ably/modules/model_common.rb', line 35 def to_json(*args) as_json.to_json(*args) end |
#to_s ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/submodules/ably-ruby/lib/ably/modules/model_common.rb', line 45 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 |