lib/ably/modules/model_common.rb in ably-0.6.2 vs lib/ably/modules/model_common.rb in ably-0.7.0
- old
+ new
@@ -1,12 +1,14 @@
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 Ably::Modules::Conversions
- include Ably::Modules::MessagePack
+ include Conversions
+ include MessagePack
# Provide a normal Hash accessor to the underlying raw message object
#
# @return [Object]
def [](key)
@@ -24,8 +26,16 @@
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