Module: Ably::Modules::ModelCommon

Overview

Common model functionality shared across many Ably::Models

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MessagePack

#to_msgpack

Instance Attribute Details

#hashInteger (readonly)

Returns Compute a hash-code for this hash. Two hashes with the same content will have the same hash code.

Returns:

  • (Integer)

    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

Returns:

  • (Object)


14
15
16
# File 'lib/ably/modules/model_common.rb', line 14

def [](key)
  attributes[key]
end

#as_jsonHash

Return a JSON ready object from the underlying #attributes using Ably naming conventions for keys

Returns:

  • (Hash)


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

Returns:

  • (String)


31
32
33
# File 'lib/ably/modules/model_common.rb', line 31

def to_json(*args)
  as_json.to_json(*args)
end