Class: Google::Cloud::Datastore::Dataset::LookupResults
- Inherits:
-
Array
- Object
- Array
- Google::Cloud::Datastore::Dataset::LookupResults
- Defined in:
- lib/google/cloud/datastore/dataset/lookup_results.rb
Overview
LookupResults is a special case Array with additional values. A LookupResults object is returned from Dataset#find_all and contains the entities as well as the Keys that were deferred from the results and the Entities that were missing in the dataset.
Please be cautious when treating the QueryResults as an Array. Many common Array methods will return a new Array instance.
Instance Attribute Summary collapse
-
#deferred ⇒ Object
Keys that were not looked up due to resource constraints.
-
#missing ⇒ Object
Entities not found, with only the key populated.
Instance Method Summary collapse
- #all(request_limit: nil) {|result| ... } ⇒ Enumerator
-
#next ⇒ LookupResults
Retrieve the next page of results.
-
#next? ⇒ Boolean
Whether there are more results available.
Instance Attribute Details
#deferred ⇒ Object
Keys that were not looked up due to resource constraints.
58 59 60 |
# File 'lib/google/cloud/datastore/dataset/lookup_results.rb', line 58 def deferred @deferred end |
#missing ⇒ Object
Entities not found, with only the key populated.
62 63 64 |
# File 'lib/google/cloud/datastore/dataset/lookup_results.rb', line 62 def missing @missing end |
Instance Method Details
#all(request_limit: nil) {|result| ... } ⇒ Enumerator
Retrieves all lookup results by repeatedly loading #next until
#next? returns false
. Calls the given block once for each
result, which is passed as the parameter.
An Enumerator is returned if no block is given.
This method may make several API calls until all lookup results are retrieved. Be sure to use as narrow a search criteria as possible. Please use with caution.
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/google/cloud/datastore/dataset/lookup_results.rb', line 169 def all request_limit: nil request_limit = request_limit.to_i if request_limit unless block_given? return enum_for(:all, request_limit: request_limit) end results = self loop do results.each { |r| yield r } if request_limit request_limit -= 1 break if request_limit < 0 end break unless results.next? results = results.next end end |
#next ⇒ LookupResults
Retrieve the next page of results.
108 109 110 111 112 113 114 115 |
# File 'lib/google/cloud/datastore/dataset/lookup_results.rb', line 108 def next return nil unless next? ensure_service! lookup_res = @service.lookup( *Array(@deferred).flatten.map(&:to_grpc), consistency: @consistency, transaction: @transaction) self.class.from_grpc lookup_res, @service, @consistency end |
#next? ⇒ Boolean
Whether there are more results available.
87 88 89 |
# File 'lib/google/cloud/datastore/dataset/lookup_results.rb', line 87 def next? Array(@deferred).any? end |