File: databasedotcom/collection.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: Databasedotcom#1
  class: Collection#5
inherits from
  Array ( Builtin-Module )
has properties
attribute: total_size [R] #6
attribute: next_page_url [R] #6
attribute: previous_page_url [R] #6
attribute: current_page_url [R] #6
attribute: client [R] #6
method: initialize / 5 #9
method: next_page? #18
method: next_page #23
method: previous_page? #28
method: previous_page #33

Class Hierarchy

Code

   1  module Databasedotcom
   2    # A collection of Sobject or Record objects that holds a single page of results, and understands how to
   3    # retrieve the next page, if any. Inherits from Array, thus, behaves as an Enumerable.
   4 
   5    class Collection < Array
   6      attr_reader :total_size, :next_page_url, :previous_page_url, :current_page_url, :client
   7 
   8      # Creates a paginatable collection. You should never need to call this.
   9      def initialize(client, total_size, next_page_url=nil, previous_page_url=nil, current_page_url=nil) #:nodoc:
  10        @client = client
  11        @total_size = total_size
  12        @next_page_url = next_page_url
  13        @previous_page_url = previous_page_url
  14        @current_page_url = current_page_url
  15      end
  16 
  17      # Does this collection have a next page?
  18      def next_page?
  19        !!self.next_page_url
  20      end
  21 
  22      # Retrieve the next page of this collection.  Returns the new collection, which is an empty collection if no next page exists
  23      def next_page
  24        self.next_page? ? @client.next_page(@next_page_url) : Databasedotcom::Collection.new(self.client, 0)
  25      end
  26 
  27      # Does this collection have a previous page?
  28      def previous_page?
  29        !!self.previous_page_url
  30      end
  31 
  32      # Retrieve the previous page of this collection. Returns the new collection, which is an empty collection if no previous page exists
  33      def previous_page
  34        self.previous_page? ? @client.previous_page(@previous_page_url) : Databasedotcom::Collection.new(self.client, 0)
  35      end
  36    end
  37  en