Sha256: 8d7f8e65619123d5170e606a4db870a6440c2a1a39a00922b822a025aba574bf

Contents?: true

Size: 1.45 KB

Versions: 35

Compression:

Stored size: 1.45 KB

Contents

module Databasedotcom
  # A collection of Sobject or Record objects that holds a single page of results, and understands how to
  # retrieve the next page, if any. Inherits from Array, thus, behaves as an Enumerable.

  class Collection < Array
    attr_reader :total_size, :next_page_url, :previous_page_url, :current_page_url, :client

    # Creates a paginatable collection. You should never need to call this.
    def initialize(client, total_size, next_page_url=nil, previous_page_url=nil, current_page_url=nil) #:nodoc:
      @client = client
      @total_size = total_size
      @next_page_url = next_page_url
      @previous_page_url = previous_page_url
      @current_page_url = current_page_url
    end

    # Does this collection have a next page?
    def next_page?
      !!self.next_page_url
    end

    # Retrieve the next page of this collection.  Returns the new collection, which is an empty collection if no next page exists
    def next_page
      self.next_page? ? @client.next_page(@next_page_url) : Databasedotcom::Collection.new(self.client, 0)
    end

    # Does this collection have a previous page?
    def previous_page?
      !!self.previous_page_url
    end

    # Retrieve the previous page of this collection. Returns the new collection, which is an empty collection if no previous page exists
    def previous_page
      self.previous_page? ? @client.previous_page(@previous_page_url) : Databasedotcom::Collection.new(self.client, 0)
    end
  end
end

Version data entries

35 entries across 35 versions & 5 rubygems

Version Path
databasedotcom-1.3.5 lib/databasedotcom/collection.rb
databasedotcom-1.3.3 lib/databasedotcom/collection.rb
glg-databasedotcom-1.3.2.1 lib/databasedotcom/collection.rb
databasedotcom-1.3.2 lib/databasedotcom/collection.rb
databasedotcom_emp-1.3.1 lib/databasedotcom/collection.rb
databasedotcom_cloudfuji-1.3.1 lib/databasedotcom/collection.rb
databasedotcom-1.3.1 lib/databasedotcom/collection.rb
databasedotcom-ejholmes-1.3.5 lib/databasedotcom/collection.rb
databasedotcom-ejholmes-1.3.4 lib/databasedotcom/collection.rb
databasedotcom-ejholmes-1.3.3 lib/databasedotcom/collection.rb
databasedotcom-ejholmes-1.3.2 lib/databasedotcom/collection.rb
databasedotcom-1.3.0 lib/databasedotcom/collection.rb
databasedotcom-1.2.7 lib/databasedotcom/collection.rb
databasedotcom-1.2.6 lib/databasedotcom/collection.rb
databasedotcom-1.2.5 lib/databasedotcom/collection.rb
databasedotcom-1.2.4 lib/databasedotcom/collection.rb
databasedotcom-1.2.3 lib/databasedotcom/collection.rb
databasedotcom-1.2.2 lib/databasedotcom/collection.rb
databasedotcom-1.2.1 lib/databasedotcom/collection.rb
databasedotcom-1.2.0 lib/databasedotcom/collection.rb