Class: Sfdc::Collection
- Inherits:
-
Object
- Object
- Sfdc::Collection
- Includes:
- Enumerable
- Defined in:
- lib/sfdc/collection.rb
Instance Method Summary collapse
-
#current_page ⇒ Object
Return array of the elements on the current page.
-
#each ⇒ Object
Yield each value on each page.
-
#has_next_page? ⇒ Boolean
Returns true if there is a pointer to the next page.
-
#initialize(hash, client) ⇒ Collection
constructor
Given a hash and client, will create an Enumerator that will lazily request Salesforce for the next page of results.
-
#next_page ⇒ Object
Returns the next page as a Sfdc::Collection if it’s available, nil otherwise.
-
#pages ⇒ Object
Return the current and all of the following pages.
-
#size ⇒ Object
(also: #length)
Return the size of the Collection without making any additional requests.
Constructor Details
#initialize(hash, client) ⇒ Collection
Given a hash and client, will create an Enumerator that will lazily request Salesforce for the next page of results.
7 8 9 10 |
# File 'lib/sfdc/collection.rb', line 7 def initialize(hash, client) @client = client @raw_page = hash end |
Instance Method Details
#current_page ⇒ Object
Return array of the elements on the current page
26 27 28 |
# File 'lib/sfdc/collection.rb', line 26 def current_page first(@raw_page['records'].size) end |
#each ⇒ Object
Yield each value on each page.
13 14 15 16 17 |
# File 'lib/sfdc/collection.rb', line 13 def each @raw_page['records'].each { |record| yield Sfdc::Mash.build(record, @client) } next_page.each { |record| yield record } if has_next_page? end |
#has_next_page? ⇒ Boolean
Returns true if there is a pointer to the next page.
36 37 38 |
# File 'lib/sfdc/collection.rb', line 36 def has_next_page? !@raw_page['nextRecordsUrl'].nil? end |
#next_page ⇒ Object
Returns the next page as a Sfdc::Collection if it’s available, nil otherwise.
41 42 43 |
# File 'lib/sfdc/collection.rb', line 41 def next_page @next_page ||= @client.get(@raw_page['nextRecordsUrl']).body if has_next_page? end |
#pages ⇒ Object
Return the current and all of the following pages.
31 32 33 |
# File 'lib/sfdc/collection.rb', line 31 def pages [self] + (has_next_page? ? next_page.pages : []) end |
#size ⇒ Object Also known as: length
Return the size of the Collection without making any additional requests.
20 21 22 |
# File 'lib/sfdc/collection.rb', line 20 def size @raw_page['totalSize'] end |