lib/submodules/ably-ruby/lib/ably/modules/model_common.rb in ably-rest-0.9.1 vs lib/submodules/ably-ruby/lib/ably/modules/model_common.rb in ably-rest-0.9.2

- old
+ new

@@ -6,10 +6,14 @@ # Common model functionality shared across many {Ably::Models} module ModelCommon include Conversions include MessagePack + def self.included(base) + base.extend(ClassMethods) + end + # Provide a normal Hash accessor to the underlying raw message object # # @return [Object] def [](key) attributes[key] @@ -34,9 +38,22 @@ # @!attribute [r] hash # @return [Integer] Compute a hash-code for this hash. Two hashes with the same content will have the same hash code def hash attributes.hash + end + + module ClassMethods + # Return a new instance of this object using the provided JSON-like object or JSON string + # @param [Hash, String] JSON-like object or JSON string + # @return a new instance o this object + def from_json(json_like_object) + if json_like_object.kind_of?(String) + new(JSON.parse(json_like_object)) + else + new(json_like_object) + end + end end private def ensure_utf8_string_for(attribute, value) if value