Class: Gcloud::Search::Index::List
- Inherits:
-
Array
- Object
- Array
- Gcloud::Search::Index::List
- Defined in:
- lib/gcloud/search/index/list.rb
Overview
Index::List is a special case Array with additional values.
Instance Attribute Summary collapse
-
#token ⇒ Object
If not empty, indicates that there are more records that match the request and this value should be passed to continue.
Class Method Summary collapse
-
.from_response(resp, conn) ⇒ Object
New Indexs::List from a response object.
Instance Method Summary collapse
-
#all ⇒ Object
Retrieves all indexes by repeatedly loading pages until #next? returns false.
-
#initialize(arr = []) ⇒ List
constructor
Create a new Index::List with an array of Index instances.
-
#next ⇒ Object
Retrieve the next page of indexes.
-
#next? ⇒ Boolean
Whether there a next page of indexes.
Constructor Details
#initialize(arr = []) ⇒ List
Create a new Index::List with an array of Index instances.
29 30 31 |
# File 'lib/gcloud/search/index/list.rb', line 29 def initialize arr = [] super arr end |
Instance Attribute Details
#token ⇒ Object
If not empty, indicates that there are more records that match the request and this value should be passed to continue.
25 26 27 |
# File 'lib/gcloud/search/index/list.rb', line 25 def token @token end |
Class Method Details
.from_response(resp, conn) ⇒ Object
New Indexs::List from a response object.
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/gcloud/search/index/list.rb', line 66 def self.from_response resp, conn #:nodoc: data = JSON.parse resp.body indexes = new(Array(data["indexes"]).map do |raw_index| Index.from_raw raw_index, conn end) indexes.instance_eval do @token = data["nextPageToken"] @connection = conn end indexes rescue JSON::ParserError raise ApiError.from_response(resp) end |
Instance Method Details
#all ⇒ Object
Retrieves all indexes by repeatedly loading pages until #next? returns false. Returns the list instance for method chaining.
55 56 57 58 59 60 61 62 |
# File 'lib/gcloud/search/index/list.rb', line 55 def all while next? next_indexes = self.next push(*next_indexes) self.token = next_indexes.token end self end |
#next ⇒ Object
Retrieve the next page of indexes.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/gcloud/search/index/list.rb', line 41 def next return nil unless next? ensure_connection! resp = @connection.list_indexes token: token if resp.success? Index::List.from_response resp, @connection else fail ApiError.from_response(resp) end end |
#next? ⇒ Boolean
Whether there a next page of indexes.
35 36 37 |
# File 'lib/gcloud/search/index/list.rb', line 35 def next? !token.nil? end |