module Aws::PageableResponse

Decorates a {Seahorse::Client::Response} with paging methods:

resp = s3.list_objects(params)
resp.last_page?
#=> false

# sends a request to receive the next response page
resp = resp.next_page
resp.last_page?
#=> true

resp.next_page
#=> raises PageableResponse::LastPageError

You can enumerate all response pages with a block

ec2.describe_instances(params).each do |page|
  # yields once per page
  page.reservations.each do |r|
    # ...
  end
end

Or using {#next_page} and {#last_page?}:

resp.last_page?
resp = resp.next_page until resp.last_page?

Attributes

pager[RW]

@return [Paging::Pager]

Public Class Methods

extended(base) click to toggle source
# File lib/aws-sdk-core/pageable_response.rb, line 33
def self.extended(base)
  base.send(:extend, Enumerable)
  base.send(:extend, UnsafeEnumerableMethods)
  base.instance_variable_set("@last_page", nil)
  base.instance_variable_set("@more_results", nil)
end

Public Instance Methods

each() { |response| ... } click to toggle source

Yields the current and each following response to the given block. @yieldparam [Response] response @return [Enumerable,nil] Returns a new Enumerable if no block is given.

# File lib/aws-sdk-core/pageable_response.rb, line 72
def each(&block)
  return enum_for(:each_page) unless block_given?
  response = self
  yield(response)
  until response.last_page?
    response = response.next_page
    yield(response)
  end
end
Also aliased as: each_page
each_page(&block)
Alias for: each
last_page?() click to toggle source

Returns `true` if there are no more results. Calling {#next_page} when this method returns `false` will raise an error. @return [Boolean]

# File lib/aws-sdk-core/pageable_response.rb, line 46
def last_page?
  if @last_page.nil?
    @last_page = !@pager.truncated?(self)
  end
  @last_page
end
next_page(params = {}) click to toggle source

@return [Seahorse::Client::Response]

# File lib/aws-sdk-core/pageable_response.rb, line 61
def next_page(params = {})
  if last_page?
    raise LastPageError.new(self)
  else
    next_response(params)
  end
end
next_page?() click to toggle source

Returns `true` if there are more results. Calling {#next_page} will return the next response. @return [Boolean]

# File lib/aws-sdk-core/pageable_response.rb, line 56
def next_page?
  !last_page?
end

Private Instance Methods

next_page_params(params) click to toggle source

@param [Hash] params A hash of additional request params to

merge into the next page request.

@return [Hash] Returns the hash of request parameters for the

next page, merging any given params.
# File lib/aws-sdk-core/pageable_response.rb, line 99
def next_page_params(params)
  context[:original_params].merge(@pager.next_tokens(self).merge(params))
end
next_response(params) click to toggle source

@param [Hash] params A hash of additional request params to

merge into the next page request.

@return [Seahorse::Client::Response] Returns the next page of

results.
# File lib/aws-sdk-core/pageable_response.rb, line 89
def next_response(params)
  params = next_page_params(params)
  request = context.client.build_request(context.operation_name, params)
  request.send_request
end