Class: Databasedotcom::Collection

Inherits:
Array
  • Object
show all
Defined in:
lib/databasedotcom/collection.rb

Overview

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.

Direct Known Subclasses

Databasedotcom::Chatter::Feed

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, total_size, next_page_url = nil, previous_page_url = nil, current_page_url = nil) ⇒ Collection

Creates a paginatable collection. You should never need to call this.



9
10
11
12
13
14
15
# File 'lib/databasedotcom/collection.rb', line 9

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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/databasedotcom/collection.rb', line 6

def client
  @client
end

#current_page_urlObject (readonly)

Returns the value of attribute current_page_url.



6
7
8
# File 'lib/databasedotcom/collection.rb', line 6

def current_page_url
  @current_page_url
end

#next_page_urlObject (readonly)

Returns the value of attribute next_page_url.



6
7
8
# File 'lib/databasedotcom/collection.rb', line 6

def next_page_url
  @next_page_url
end

#previous_page_urlObject (readonly)

Returns the value of attribute previous_page_url.



6
7
8
# File 'lib/databasedotcom/collection.rb', line 6

def previous_page_url
  @previous_page_url
end

#total_sizeObject (readonly)

Returns the value of attribute total_size.



6
7
8
# File 'lib/databasedotcom/collection.rb', line 6

def total_size
  @total_size
end

Instance Method Details

#next_pageObject

Retrieve the next page of this collection. Returns the new collection, which is an empty collection if no next page exists



23
24
25
# File 'lib/databasedotcom/collection.rb', line 23

def next_page
  self.next_page? ? @client.next_page(@next_page_url) : Databasedotcom::Collection.new(self.client, 0)
end

#next_page?Boolean

Does this collection have a next page?

Returns:

  • (Boolean)


18
19
20
# File 'lib/databasedotcom/collection.rb', line 18

def next_page?
  !!self.next_page_url
end

#previous_pageObject

Retrieve the previous page of this collection. Returns the new collection, which is an empty collection if no previous page exists



33
34
35
# File 'lib/databasedotcom/collection.rb', line 33

def previous_page
  self.previous_page? ? @client.previous_page(@previous_page_url) : Databasedotcom::Collection.new(self.client, 0)
end

#previous_page?Boolean

Does this collection have a previous page?

Returns:

  • (Boolean)


28
29
30
# File 'lib/databasedotcom/collection.rb', line 28

def previous_page?
  !!self.previous_page_url
end