class Contentful::Includes
The includes hashes returned when include_level is specified
Attributes
Public Class Methods
Source
# File lib/contentful/includes.rb, line 15 def self.from_response(json, raw = true) includes = if raw json['items'].dup else json['items'].map(&:raw) end %w[Entry Asset].each do |type| includes.concat(json['includes'].fetch(type, [])) if json.fetch('includes', {}).key?(type) end new includes || [] end
Source
# File lib/contentful/includes.rb, line 10 def initialize(items = [], lookup = nil) self.items = items self.lookup = lookup || build_lookup end
Public Instance Methods
Source
# File lib/contentful/includes.rb, line 42 def +(other) # If we're being asked to add to itself, just return without duplicating return self if self == other dup.tap do |copy| copy.items += other.items copy.lookup.merge!(other.lookup) end end
Source
# File lib/contentful/includes.rb, line 38 def ==(other) object_id == other.object_id || lookup == other.lookup end
If the lookups are the same then these two objects are effectively the same
Source
# File lib/contentful/includes.rb, line 52 def dup self.class.new(items.dup, lookup.dup) end
Source
# File lib/contentful/includes.rb, line 29 def find_link(link) key = "#{link['sys']['linkType']}:#{link['sys']['id']}" lookup[key] end
Source
# File lib/contentful/includes.rb, line 60 def marshal_load(array) self.items = array self.lookup = build_lookup end
Private Instance Methods
Source
# File lib/contentful/includes.rb, line 67 def build_lookup items.each_with_object({}) do |i, h| key = "#{i['sys']['type']}:#{i['sys']['id']}" h[key] = i end end