Class: Gapic::PagedEnumerable
- Inherits:
-
Object
- Object
- Gapic::PagedEnumerable
- Includes:
- Enumerable
- Defined in:
- lib/gapic/paged_enumerable.rb
Overview
A class to provide the Enumerable interface to the response of a paginated method. PagedEnumerable assumes response message holds a list of resources and the token to the next page.
PagedEnumerable provides the enumerations over the resource data, and also provides the enumerations over the pages themselves.
Defined Under Namespace
Classes: Page
Instance Attribute Summary collapse
-
#page ⇒ Object
readonly
Returns the value of attribute page.
Instance Method Summary collapse
-
#each {|Object| ... } ⇒ Object
Iterate over the resources.
-
#each_page {|Page| ... } ⇒ Object
Iterate over the pages.
-
#next_page! ⇒ Page
(also: #next_page)
Update the response in the current page.
-
#next_page? ⇒ Boolean
True if it has the next page.
-
#next_page_token ⇒ String
The page token to be used for the next RPC call.
-
#response ⇒ Object
The current response object, for the current page.
Instance Attribute Details
#page ⇒ Object (readonly)
Returns the value of attribute page.
48 49 50 |
# File 'lib/gapic/paged_enumerable.rb', line 48 def page @page end |
Instance Method Details
#each {|Object| ... } ⇒ Object
Iterate over the resources.
83 84 85 86 87 88 89 |
# File 'lib/gapic/paged_enumerable.rb', line 83 def each &block return enum_for :each unless block_given? each_page do |page| page.each(&block) end end |
#each_page {|Page| ... } ⇒ Object
Iterate over the pages.
98 99 100 101 102 103 104 105 106 |
# File 'lib/gapic/paged_enumerable.rb', line 98 def each_page return enum_for :each_page unless block_given? loop do break if @page.nil? yield @page next_page! end end |
#next_page! ⇒ Page Also known as: next_page
Update the response in the current page.
120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/gapic/paged_enumerable.rb', line 120 def next_page! unless next_page? @page = nil return @page end next_request = @request.dup next_request.page_token = @page.next_page_token @grpc_stub.call_rpc @method_name, next_request, options: @options do |next_response, next_operation| @page = Page.new next_response, @resource_field, next_operation, format_resource: @format_resource end @page end |
#next_page? ⇒ Boolean
True if it has the next page.
111 112 113 |
# File 'lib/gapic/paged_enumerable.rb', line 111 def next_page? @page.next_page_token? end |
#next_page_token ⇒ String
The page token to be used for the next RPC call.
140 141 142 |
# File 'lib/gapic/paged_enumerable.rb', line 140 def next_page_token @page.next_page_token end |
#response ⇒ Object
The current response object, for the current page.
149 150 151 |
# File 'lib/gapic/paged_enumerable.rb', line 149 def response @page.response end |