class Gapic::Rest::PagedEnumerable


@return [Page] The current page object.
@attribute [r] page
end
paged_enumerable.next_page
break if paged_enumerable.next_page?
do_something(page)
page = paged_enumerable.page
while some_condition()
@example more exact operations over pages.
end
page.each { |resource| puts resource }
paged_enumerable.each_page do |page|
@example Enumerable over pages.
paged_enumerable.each_page { |page| puts page }
@example per-page iteration.
paged_enumerable.each { |resource| puts resource }
@example normal iteration over resources.
pages themselves.
PagedEnumerable provides the enumerations over the resource data, and also provides the enumerations over the
PagedEnumerable assumes response message holds a list of resources and the token to the next page.
A class to provide the Enumerable interface to the response of a REST paginated method.
#

def each &block

Returns:
  • (Enumerator) - if no block is provided

Other tags:
    Yield: - Gives the resource objects in the stream.
def each &block
  return enum_for :each unless block_given?
  each_page do |page|
    page.each(&block)
  end
end

def each_page

Returns:
  • (Enumerator) - if no block is provided

Other tags:
    Yield: - Gives the pages in the stream.
def each_page
  return enum_for :each_page unless block_given?
  loop do
    break if @page.nil?
    yield @page
    next_page!
  end
end

def initialize service_stub, method_name, resource_field_name, request, response, options, format_resource: nil

Parameters:
  • format_resource (Proc) -- A Proc object to format the resource object. The Proc should accept response as an
  • options (Gapic::CallOptions) -- The options for making the RPC call.
  • response (Object) -- The response object.
  • request (Object) -- The request object.
  • method_name (Symbol) -- The REST method name that is being wrapped.
  • service_stub (Object) -- The REST service_stub with the baseline implementation for the wrapped method.

Other tags:
    Private: -
def initialize service_stub, method_name, resource_field_name, request, response, options, format_resource: nil
  @service_stub = service_stub
  @method_name = method_name
  @resource_field_name = resource_field_name
  @request = request
  @response = response
  @options = options
  @format_resource = format_resource
  @page = Page.new response, resource_field_name, format_resource: @format_resource
end

def next_page!

Returns:
  • (Page, nil) - the new page object.
def next_page!
  unless next_page?
    @page = nil
    return @page
  end
  next_request = @request.dup
  next_request.page_token = @page.next_page_token
  @response = @service_stub.send @method_name, next_request, @options
  @page = Page.new @response, @resource_field_name, format_resource: @format_resource
end

def next_page?

Returns:
  • (Boolean) -
def next_page?
  !next_page_token.nil? && !next_page_token.empty?
end

def next_page_token

Returns:
  • (String, nil) -
def next_page_token
  @page&.next_page_token
end

def response

Returns:
  • (Object, nil) -
def response
  @page&.response
end