class Gapic::PagedEnumerable::Page
A class to represent a page in a PagedEnumerable
. This also implements Enumerable, so it can iterate over the resource elements.
@attribute [r] response
@return [Object] the response object for the page.
@attribute [r] operation
@return [::GRPC::ActiveCall::Operation] the RPC operation for the page.
Attributes
operation[R]
response[R]
Public Class Methods
new(response, resource_field, operation, format_resource: nil)
click to toggle source
@private @param response [Object] The response object for the page. @param resource_field [String] The name of the field in response which holds the resources. @param operation [::GRPC::ActiveCall::Operation] the RPC operation for the page. @param format_resource [Proc] A Proc object to format the resource object. The Proc should accept response as an
argument, and return a formatted resource object. Optional.
# File lib/gapic/paged_enumerable.rb, line 212 def initialize response, resource_field, operation, format_resource: nil @response = response @resource_field = resource_field @operation = operation @format_resource = format_resource end
Public Instance Methods
each() { |resource| ... }
click to toggle source
Iterate over the resources.
@yield [Object] Gives the resource objects in the page.
# File lib/gapic/paged_enumerable.rb, line 224 def each return enum_for :each unless block_given? return if @response.nil? # We trust that the field exists and is an Enumerable @response[@resource_field].each do |resource| resource = @format_resource.call resource if @format_resource yield resource end end
next_page_token()
click to toggle source
The page token to be used for the next RPC call.
@return [String]
# File lib/gapic/paged_enumerable.rb, line 241 def next_page_token return if @response.nil? @response.next_page_token end
next_page_token?()
click to toggle source
Truthiness of next_page_token.
@return [Boolean]
# File lib/gapic/paged_enumerable.rb, line 252 def next_page_token? return if @response.nil? !@response.next_page_token.empty? end