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
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 90 91 |
# File 'lib/gapic/paged_enumerable.rb', line 83 def each return enum_for :each unless block_given? each_page do |page| page.each do |obj| yield obj end end end |
#each_page {|Page| ... } ⇒ Object
Iterate over the pages.
100 101 102 103 104 105 106 107 108 |
# File 'lib/gapic/paged_enumerable.rb', line 100 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
Update the response in the current page.
122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/gapic/paged_enumerable.rb', line 122 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.
113 114 115 |
# File 'lib/gapic/paged_enumerable.rb', line 113 def next_page? @page.next_page_token? end |
#next_page_token ⇒ String
The page token to be used for the next RPC call.
141 142 143 |
# File 'lib/gapic/paged_enumerable.rb', line 141 def next_page_token @page.next_page_token end |
#response ⇒ Object
The current response object, for the current page.
150 151 152 |
# File 'lib/gapic/paged_enumerable.rb', line 150 def response @page.response end |