Module: Aws::PageableResponse
- Defined in:
- lib/aws-sdk-core/pageable_response.rb
Overview
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?
Defined Under Namespace
Modules: UnsafeEnumerableMethods Classes: LastPageError
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#each {|response| ... } ⇒ Enumerable?
(also: #each_page)
Yields the current and each following response to the given block.
-
#last_page? ⇒ Boolean
Returns ‘true` if there are no more results.
- #next_page(params = {}) ⇒ Seahorse::Client::Response
-
#next_page? ⇒ Boolean
Returns ‘true` if there are more results.
Instance Attribute Details
#pager ⇒ Paging::Pager
41 42 43 |
# File 'lib/aws-sdk-core/pageable_response.rb', line 41 def pager @pager end |
Class Method Details
.extended(base) ⇒ Object
33 34 35 36 37 38 |
# 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 |
Instance Method Details
#each {|response| ... } ⇒ Enumerable? Also known as: each_page
Yields the current and each following response to the given block.
72 73 74 75 76 77 78 79 80 |
# 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 |
#last_page? ⇒ Boolean
Returns ‘true` if there are no more results. Calling #next_page when this method returns `false` will raise an error.
46 47 48 49 50 51 |
# 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 = {}) ⇒ Seahorse::Client::Response
61 62 63 64 65 66 67 |
# 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? ⇒ Boolean
Returns ‘true` if there are more results. Calling #next_page will return the next response.
56 57 58 |
# File 'lib/aws-sdk-core/pageable_response.rb', line 56 def next_page? !last_page? end |