Sha256: 498e83c2c4340300d32f44ee11c8b0434b6c607d429be3beeabdcb70659ded34

Contents?: true

Size: 1.15 KB

Versions: 33

Compression:

Stored size: 1.15 KB

Contents

require_relative 'resource'
require_relative 'resource/array_like'

module Contentful
  module Management
    # Resource Class for Arrays (e.g. search results)
    # @see _ https://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)
    class Array
      # @private
      DEFAULT_LIMIT = 100

      include Contentful::Management::Resource
      include Contentful::Management::Resource::ArrayLike
      include Contentful::Management::Resource::SystemProperties

      property :items
      property :skip, :integer
      property :total, :integer
      property :limit, :integer

      # Simplifies pagination
      def next_page
        if request
          new_skip = (skip || 0) + (limit || DEFAULT_LIMIT)
          new_request = request.copy
          new_request.instance_variable_set(:@query, {}) if new_request.query.nil?
          new_request.query[:skip] = new_skip
          response = new_request.get
          ResourceBuilder.new(response, client).run
        else
          false
        end
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
contentful-management-3.8.0 lib/contentful/management/array.rb
contentful-management-3.7.0 lib/contentful/management/array.rb
contentful-management-3.6.0 lib/contentful/management/array.rb
contentful-management-3.5.0 lib/contentful/management/array.rb
contentful-management-3.4.0 lib/contentful/management/array.rb
contentful-management-3.3.0 lib/contentful/management/array.rb
contentful-management-3.2.0 lib/contentful/management/array.rb
contentful-management-3.1.0 lib/contentful/management/array.rb
contentful-management-3.0.0 lib/contentful/management/array.rb
contentful-management-2.13.1 lib/contentful/management/array.rb
contentful-management-2.13.0 lib/contentful/management/array.rb
contentful-management-2.12.1 lib/contentful/management/array.rb
contentful-management-2.12.0 lib/contentful/management/array.rb
contentful-management-2.11.0 lib/contentful/management/array.rb
contentful-management-2.10.0 lib/contentful/management/array.rb
contentful-management-2.9.1 lib/contentful/management/array.rb
contentful-management-2.9.0 lib/contentful/management/array.rb
contentful-management-2.8.2 lib/contentful/management/array.rb
contentful-management-2.8.1 lib/contentful/management/array.rb
contentful-management-2.8.0 lib/contentful/management/array.rb