lib/wcc/contentful/indexed_representation.rb in wcc-contentful-0.2.2 vs lib/wcc/contentful/indexed_representation.rb in wcc-contentful-0.3.0.pre.rc
- old
+ new
@@ -13,10 +13,11 @@
delegate :each_with_object, to: :@types
delegate :each_value, to: :@types
def []=(id, value)
raise ArgumentError unless value.is_a?(ContentType)
+
@types[id] = value
end
def self.from_json(hash)
hash = JSON.parse(hash) if hash.is_a?(String)
@@ -37,10 +38,11 @@
end
def ==(other)
my_keys = keys
return false unless my_keys == other.keys
+
my_keys.all? { |k| self[k] == other[k] }
end
class ContentType
ATTRIBUTES = %i[
@@ -52,10 +54,11 @@
attr_accessor(*ATTRIBUTES)
def initialize(hash_or_id = nil)
@fields = {}
return unless hash_or_id
+
if hash_or_id.is_a?(String)
@name = hash_or_id
return
end
@@ -106,15 +109,17 @@
def type=(raw_type)
unless TYPES.include?(raw_type)
raise ArgumentError, "Unknown type #{raw_type}, expected one of: #{TYPES}"
end
+
@type = raw_type
end
def initialize(hash_or_id = nil)
return unless hash_or_id
+
if hash_or_id.is_a?(String)
@name = hash_or_id
return
end
@@ -126,9 +131,10 @@
if raw_type = hash_or_id.delete('type')
raw_type = raw_type.to_sym
unless TYPES.include?(raw_type)
raise ArgumentError, "Unknown type #{raw_type}, expected one of: #{TYPES}"
end
+
@type = raw_type
end
hash_or_id.each { |k, v| public_send("#{k}=", v) }
end