class Contentful::Array
Resource Class for Arrays (e.g. search results) @see _ www.contentful.com/developers/documentation/content-delivery-api/#arrays @note It also provides an each
method and includes Ruby’s Enumerable module (gives you methods like min, first, etc)
Constants
- DEFAULT_LIMIT
-
@private
Attributes
Public Class Methods
Source
# File lib/contentful/array.rb, line 17 def initialize(item = nil, configuration = { default_locale: Contentful::Client::DEFAULT_CONFIGURATION[:default_locale] }, endpoint = '', query = {}, *) super(item, configuration) @endpoint = endpoint @total = item.fetch('total', nil) @limit = item.fetch('limit', nil) @skip = item.fetch('skip', nil) @items = item.fetch('items', []) @query = query end
Calls superclass method
Public Instance Methods
Source
# File lib/contentful/array.rb, line 60 def inspect "<#{repr_name} total=#{total} skip=#{skip} limit=#{limit}>" end
@private
Source
# File lib/contentful/array.rb, line 35 def marshal_dump super.merge(endpoint: endpoint, query: query) end
@private
Calls superclass method
Source
# File lib/contentful/array.rb, line 40 def marshal_load(raw_object) super @endpoint = raw_object[:endpoint] @total = raw.fetch('total', nil) @limit = raw.fetch('limit', nil) @skip = raw.fetch('skip', nil) @query = raw_object[:query] @items = raw.fetch('items', []).map do |item| require_relative 'resource_builder' ResourceBuilder.new( item.raw, raw_object[:configuration].merge(includes_for_single: Includes.from_response(raw, false)), item.respond_to?(:localized) ? item.localized : false, 0, raw_object[:configuration][:errors] || [] ).run end end
@private
Calls superclass method
Source
# File lib/contentful/array.rb, line 67 def next_page(client = nil) return false if client.nil? return false if items.first.nil? new_skip = (skip || 0) + (limit || DEFAULT_LIMIT) plurals = { 'Space' => 'spaces', 'ContentType' => 'content_types', 'Entry' => 'entries', 'Asset' => 'assets', 'Locale' => 'locales' } client.public_send(plurals[items.first.type], query.merge(limit: limit, skip: new_skip)) end
Simplifies pagination
@return [Contentful::Array, false]