Class: Recurly::Pager
- Inherits:
-
Object
- Object
- Recurly::Pager
- Defined in:
- lib/recurly/pager.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#next ⇒ Object
readonly
Returns the value of attribute next.
Instance Method Summary collapse
-
#each(&block) ⇒ Object
Enumerates each item on the server.
-
#each_page(&block) ⇒ Object
Enumerates each “page” from the server.
- #has_more? ⇒ Boolean
-
#initialize(client:, path:, options: {}) ⇒ Pager
constructor
A new instance of Pager.
- #requires_client? ⇒ Boolean
Constructor Details
#initialize(client:, path:, options: {}) ⇒ Pager
Returns a new instance of Pager.
6 7 8 9 10 11 |
# File 'lib/recurly/pager.rb', line 6 def initialize(client:, path:, options: {}) @client = client @path = path = map_array_params() @next = build_path(@path, ) end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
3 4 5 |
# File 'lib/recurly/pager.rb', line 3 def client @client end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
4 5 6 |
# File 'lib/recurly/pager.rb', line 4 def data @data end |
#next ⇒ Object (readonly)
Returns the value of attribute next.
4 5 6 |
# File 'lib/recurly/pager.rb', line 4 def next @next end |
Instance Method Details
#each(&block) ⇒ Object
Enumerates each item on the server. Each item is yielded to the block presenting the effect of a continuous stream of items. In reality, the pager is fetching blocks of data (pages) under the hood. This method yields a given block with the next item to process.
56 57 58 59 60 61 62 |
# File 'lib/recurly/pager.rb', line 56 def each(&block) if block_given? item_enumerator.each(&block) else item_enumerator end end |
#each_page(&block) ⇒ Object
Enumerates each “page” from the server. This method yields a given block with the array of items in the page data and the page number the pagination is on page_num which is 0-indexed.
33 34 35 36 37 38 39 |
# File 'lib/recurly/pager.rb', line 33 def each_page(&block) if block_given? page_enumerator.each(&block) else page_enumerator end end |
#has_more? ⇒ Boolean
64 65 66 |
# File 'lib/recurly/pager.rb', line 64 def has_more? !!@has_more end |
#requires_client? ⇒ Boolean
68 69 70 |
# File 'lib/recurly/pager.rb', line 68 def requires_client? true end |