Sha256: d4a3cdad4361eee5172a837604514e0a1c1768292ac9f9f9d5b65284383223d7

Contents?: true

Size: 1.08 KB

Versions: 13

Compression:

Stored size: 1.08 KB

Contents

require 'base64'
require 'ably/modules/conversions'
require 'ably/modules/message_pack'

module Ably::Modules
  # Common model functionality shared across many {Ably::Models}
  module ModelCommon
    include Conversions
    include MessagePack

    # Provide a normal Hash accessor to the underlying raw message object
    #
    # @return [Object]
    def [](key)
      hash[key]
    end

    def ==(other)
      other.kind_of?(self.class) &&
        hash == other.hash
    end

    # Return a JSON ready object from the underlying #hash using Ably naming conventions for keys
    def as_json
      hash.as_json.dup
    end

    # Stringify the JSON representation of this object from the underlying #hash
    def to_json(*args)
      as_json.to_json(*args)
    end

    private
    def ensure_utf8_string_for(attribute, value)
      if value
        raise ArgumentError, "#{attribute} must be a String" unless value.kind_of?(String)
        raise ArgumentError, "#{attribute} cannot use ASCII_8BIT encoding, please use UTF_8 encoding" unless value.encoding == Encoding::UTF_8
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
ably-rest-0.8.2 lib/submodules/ably-ruby/lib/ably/modules/model_common.rb
ably-0.8.2 lib/ably/modules/model_common.rb
ably-0.8.1 lib/ably/modules/model_common.rb
ably-rest-0.8.1 lib/submodules/ably-ruby/lib/ably/modules/model_common.rb
ably-0.8.0 lib/ably/modules/model_common.rb
ably-0.7.6 lib/ably/modules/model_common.rb
ably-rest-0.7.5 lib/submodules/ably-ruby/lib/ably/modules/model_common.rb
ably-0.7.5 lib/ably/modules/model_common.rb
ably-0.7.4 lib/ably/modules/model_common.rb
ably-rest-0.7.3 lib/submodules/ably-ruby/lib/ably/modules/model_common.rb
ably-0.7.2 lib/ably/modules/model_common.rb
ably-0.7.1 lib/ably/modules/model_common.rb
ably-0.7.0 lib/ably/modules/model_common.rb