Class: Databasedotcom::Collection
- Inherits:
-
Array
- Object
- Array
- Databasedotcom::Collection
- 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
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#current_page_url ⇒ Object
readonly
Returns the value of attribute current_page_url.
-
#next_page_url ⇒ Object
readonly
Returns the value of attribute next_page_url.
-
#previous_page_url ⇒ Object
readonly
Returns the value of attribute previous_page_url.
-
#total_size ⇒ Object
readonly
Returns the value of attribute total_size.
Instance Method Summary collapse
-
#initialize(client, total_size, next_page_url = nil, previous_page_url = nil, current_page_url = nil) ⇒ Collection
constructor
Creates a paginatable collection.
-
#next_page ⇒ Object
Retrieve the next page of this collection.
-
#next_page? ⇒ Boolean
Does this collection have a next page?.
-
#previous_page ⇒ Object
Retrieve the previous page of this collection.
-
#previous_page? ⇒ Boolean
Does this collection have a previous page?.
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
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/databasedotcom/collection.rb', line 6 def client @client end |
#current_page_url ⇒ Object (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_url ⇒ Object (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_url ⇒ Object (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_size ⇒ Object (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_page ⇒ Object
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?
18 19 20 |
# File 'lib/databasedotcom/collection.rb', line 18 def next_page? !!self.next_page_url end |
#previous_page ⇒ Object
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?
28 29 30 |
# File 'lib/databasedotcom/collection.rb', line 28 def previous_page? !!self.previous_page_url end |