Class: Google::Gax::PagedEnumerable::Page
- Inherits:
-
Object
- Object
- Google::Gax::PagedEnumerable::Page
- Includes:
- Enumerable
- Defined in:
- lib/google/gax/api_callable.rb
Overview
A class to represent a page in a PagedEnumerable. This also implements Enumerable, so it can iterate over the resource elements.
Instance Attribute Summary collapse
-
#next_page_token ⇒ Object
readonly
The page token to be used for the next API call.
-
#response ⇒ Object
readonly
The actual response object.
Instance Method Summary collapse
-
#dup_with(response) ⇒ Object
Creates another instance of Page with replacing the new response.
-
#each {|Object| ... } ⇒ Object
Iterate over the resources.
-
#initialize(response, response_page_token_field, resource_field) ⇒ Page
constructor
A new instance of Page.
-
#next_page_token? ⇒ Boolean
Truthiness of next_page_token.
Constructor Details
#initialize(response, response_page_token_field, resource_field) ⇒ Page
Returns a new instance of Page.
87 88 89 90 91 |
# File 'lib/google/gax/api_callable.rb', line 87 def initialize(response, response_page_token_field, resource_field) @response = response @response_page_token_field = response_page_token_field @resource_field = resource_field end |
Instance Attribute Details
#next_page_token ⇒ Object (readonly)
Returns the page token to be used for the next API call.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/google/gax/api_callable.rb', line 77 class Page include Enumerable attr_reader :response # @param response [Object] # The response object for the page. # @param response_page_token_field [String] # The name of the field in response which holds the next page token. # @param resource_field [String] # The name of the field in response which holds the resources. def initialize(response, response_page_token_field, resource_field) @response = response @response_page_token_field = response_page_token_field @resource_field = resource_field end # Creates another instance of Page with replacing the new response. # @param response [Object] a new response object. def dup_with(response) self.class.new(response, @response_page_token_field, @resource_field) end # Iterate over the resources. # @yield [Object] Gives the resource objects in the page. def each @response[@resource_field].each do |obj| yield obj end end def next_page_token @response[@response_page_token_field] end # Truthiness of next_page_token. def next_page_token? !@response.nil? && !next_page_token.nil? && next_page_token != 0 && (!next_page_token.respond_to?(:empty?) || !next_page_token.empty?) end end |
#response ⇒ Object (readonly)
Returns the actual response object.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/google/gax/api_callable.rb', line 77 class Page include Enumerable attr_reader :response # @param response [Object] # The response object for the page. # @param response_page_token_field [String] # The name of the field in response which holds the next page token. # @param resource_field [String] # The name of the field in response which holds the resources. def initialize(response, response_page_token_field, resource_field) @response = response @response_page_token_field = response_page_token_field @resource_field = resource_field end # Creates another instance of Page with replacing the new response. # @param response [Object] a new response object. def dup_with(response) self.class.new(response, @response_page_token_field, @resource_field) end # Iterate over the resources. # @yield [Object] Gives the resource objects in the page. def each @response[@resource_field].each do |obj| yield obj end end def next_page_token @response[@response_page_token_field] end # Truthiness of next_page_token. def next_page_token? !@response.nil? && !next_page_token.nil? && next_page_token != 0 && (!next_page_token.respond_to?(:empty?) || !next_page_token.empty?) end end |
Instance Method Details
#dup_with(response) ⇒ Object
Creates another instance of Page with replacing the new response.
95 96 97 |
# File 'lib/google/gax/api_callable.rb', line 95 def dup_with(response) self.class.new(response, @response_page_token_field, @resource_field) end |
#each {|Object| ... } ⇒ Object
Iterate over the resources.
101 102 103 104 105 |
# File 'lib/google/gax/api_callable.rb', line 101 def each @response[@resource_field].each do |obj| yield obj end end |
#next_page_token? ⇒ Boolean
Truthiness of next_page_token.
112 113 114 115 |
# File 'lib/google/gax/api_callable.rb', line 112 def next_page_token? !@response.nil? && !next_page_token.nil? && next_page_token != 0 && (!next_page_token.respond_to?(:empty?) || !next_page_token.empty?) end |