module Ably::Modules::ModelCommon
Common model functionality shared across many {Ably::Models}
Public Class Methods
Source
# File lib/ably/modules/model_common.rb, line 11 def self.included(base) base.extend(ClassMethods) end
Public Instance Methods
Source
# File lib/ably/modules/model_common.rb, line 23 def ==(other) other.kind_of?(self.class) && attributes == other.attributes end
Source
# File lib/ably/modules/model_common.rb, line 19 def [](key) attributes[key] end
Provide a normal Hash accessor to the underlying raw message object
@return [Object]
Source
# File lib/ably/modules/model_common.rb, line 32 def as_json(*args) attributes.as_json.reject { |key, val| val.nil? } end
Return a JSON ready object from the underlying attributes using Ably
naming conventions for keys
@return [Hash]
Source
# File lib/ably/modules/model_common.rb, line 46 def hash attributes.hash end
@!attribute [r] hash @return [Integer] Compute a hash-code for this hash. Two hashes with the same content will have the same hash code
Source
# File lib/ably/modules/model_common.rb, line 40 def to_json(*args) as_json.to_json(*args) end
Stringify the JSON representation of this object from the underlying attributes
@return [String]
Source
# File 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
Private Instance Methods
Source
# File lib/ably/modules/model_common.rb, line 77 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