google-cloud-firestore 1.4.4 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHENTICATION.md +1 -1
  3. data/CHANGELOG.md +55 -0
  4. data/lib/google-cloud-firestore.rb +15 -21
  5. data/lib/google/cloud/firestore.rb +12 -23
  6. data/lib/google/cloud/firestore/client.rb +12 -14
  7. data/lib/google/cloud/firestore/collection_reference.rb +1 -0
  8. data/lib/google/cloud/firestore/collection_reference_list.rb +137 -0
  9. data/lib/google/cloud/firestore/convert.rb +39 -39
  10. data/lib/google/cloud/firestore/credentials.rb +2 -2
  11. data/lib/google/cloud/firestore/document_listener.rb +86 -7
  12. data/lib/google/cloud/firestore/document_reference.rb +9 -10
  13. data/lib/google/cloud/firestore/document_reference/list.rb +2 -2
  14. data/lib/google/cloud/firestore/document_snapshot.rb +5 -6
  15. data/lib/google/cloud/firestore/query.rb +127 -34
  16. data/lib/google/cloud/firestore/query_listener.rb +82 -1
  17. data/lib/google/cloud/firestore/service.rb +63 -104
  18. data/lib/google/cloud/firestore/transaction.rb +2 -2
  19. data/lib/google/cloud/firestore/version.rb +1 -1
  20. data/lib/google/cloud/firestore/watch/inventory.rb +2 -0
  21. data/lib/google/cloud/firestore/watch/listener.rb +32 -25
  22. data/lib/google/cloud/firestore/watch/order.rb +1 -1
  23. metadata +9 -107
  24. data/lib/google/cloud/firestore/admin.rb +0 -144
  25. data/lib/google/cloud/firestore/admin/v1.rb +0 -151
  26. data/lib/google/cloud/firestore/admin/v1/credentials.rb +0 -44
  27. data/lib/google/cloud/firestore/admin/v1/doc/google/firestore/admin/v1/field.rb +0 -86
  28. data/lib/google/cloud/firestore/admin/v1/doc/google/firestore/admin/v1/firestore_admin.rb +0 -161
  29. data/lib/google/cloud/firestore/admin/v1/doc/google/firestore/admin/v1/index.rb +0 -142
  30. data/lib/google/cloud/firestore/admin/v1/doc/google/longrunning/operations.rb +0 -51
  31. data/lib/google/cloud/firestore/admin/v1/doc/google/protobuf/any.rb +0 -131
  32. data/lib/google/cloud/firestore/admin/v1/doc/google/protobuf/empty.rb +0 -29
  33. data/lib/google/cloud/firestore/admin/v1/doc/google/protobuf/field_mask.rb +0 -222
  34. data/lib/google/cloud/firestore/admin/v1/doc/google/rpc/status.rb +0 -39
  35. data/lib/google/cloud/firestore/admin/v1/firestore_admin_client.rb +0 -902
  36. data/lib/google/cloud/firestore/admin/v1/firestore_admin_client_config.json +0 -76
  37. data/lib/google/cloud/firestore/v1.rb +0 -152
  38. data/lib/google/cloud/firestore/v1/credentials.rb +0 -42
  39. data/lib/google/cloud/firestore/v1/doc/google/firestore/v1/common.rb +0 -64
  40. data/lib/google/cloud/firestore/v1/doc/google/firestore/v1/document.rb +0 -136
  41. data/lib/google/cloud/firestore/v1/doc/google/firestore/v1/firestore.rb +0 -566
  42. data/lib/google/cloud/firestore/v1/doc/google/firestore/v1/query.rb +0 -227
  43. data/lib/google/cloud/firestore/v1/doc/google/firestore/v1/write.rb +0 -241
  44. data/lib/google/cloud/firestore/v1/doc/google/protobuf/any.rb +0 -131
  45. data/lib/google/cloud/firestore/v1/doc/google/protobuf/empty.rb +0 -29
  46. data/lib/google/cloud/firestore/v1/doc/google/protobuf/timestamp.rb +0 -113
  47. data/lib/google/cloud/firestore/v1/doc/google/protobuf/wrappers.rb +0 -26
  48. data/lib/google/cloud/firestore/v1/doc/google/rpc/status.rb +0 -39
  49. data/lib/google/cloud/firestore/v1/firestore_client.rb +0 -1011
  50. data/lib/google/cloud/firestore/v1/firestore_client_config.json +0 -105
  51. data/lib/google/cloud/firestore/v1beta1.rb +0 -162
  52. data/lib/google/cloud/firestore/v1beta1/credentials.rb +0 -42
  53. data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/common.rb +0 -64
  54. data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/document.rb +0 -136
  55. data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/firestore.rb +0 -564
  56. data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/query.rb +0 -227
  57. data/lib/google/cloud/firestore/v1beta1/doc/google/firestore/v1beta1/write.rb +0 -237
  58. data/lib/google/cloud/firestore/v1beta1/doc/google/protobuf/any.rb +0 -131
  59. data/lib/google/cloud/firestore/v1beta1/doc/google/protobuf/empty.rb +0 -29
  60. data/lib/google/cloud/firestore/v1beta1/doc/google/protobuf/timestamp.rb +0 -113
  61. data/lib/google/cloud/firestore/v1beta1/doc/google/protobuf/wrappers.rb +0 -26
  62. data/lib/google/cloud/firestore/v1beta1/doc/google/rpc/status.rb +0 -39
  63. data/lib/google/cloud/firestore/v1beta1/firestore_client.rb +0 -1021
  64. data/lib/google/cloud/firestore/v1beta1/firestore_client_config.json +0 -100
  65. data/lib/google/firestore/admin/v1/field_pb.rb +0 -32
  66. data/lib/google/firestore/admin/v1/firestore_admin_pb.rb +0 -84
  67. data/lib/google/firestore/admin/v1/firestore_admin_services_pb.rb +0 -94
  68. data/lib/google/firestore/admin/v1/index_pb.rb +0 -58
  69. data/lib/google/firestore/admin/v1/location_pb.rb +0 -22
  70. data/lib/google/firestore/admin/v1/operation_pb.rb +0 -90
  71. data/lib/google/firestore/v1/common_pb.rb +0 -45
  72. data/lib/google/firestore/v1/document_pb.rb +0 -50
  73. data/lib/google/firestore/v1/firestore_pb.rb +0 -222
  74. data/lib/google/firestore/v1/firestore_services_pb.rb +0 -80
  75. data/lib/google/firestore/v1/query_pb.rb +0 -107
  76. data/lib/google/firestore/v1/write_pb.rb +0 -80
  77. data/lib/google/firestore/v1beta1/common_pb.rb +0 -45
  78. data/lib/google/firestore/v1beta1/document_pb.rb +0 -50
  79. data/lib/google/firestore/v1beta1/firestore_pb.rb +0 -222
  80. data/lib/google/firestore/v1beta1/firestore_services_pb.rb +0 -89
  81. data/lib/google/firestore/v1beta1/query_pb.rb +0 -107
  82. data/lib/google/firestore/v1beta1/write_pb.rb +0 -79
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 767d0de57b4cb69eb636c2dd85e95da99bab28356514daeae0cb29e87aac8989
4
- data.tar.gz: 9a2c8ebd59ef8694fcfe1cd78c027acca7442ae638c90b125dbde4f7adc4a8e0
3
+ metadata.gz: e39fbfebed5714a9eeb9fe9e1e22e8bf0ac29e16b34c1683b0e35bd9bde3d754
4
+ data.tar.gz: d7a8363434c9e48dc134acbc863020e89d89bcc0af7c95148e4a9f0542a3554c
5
5
  SHA512:
6
- metadata.gz: 93d63f0d8d61ff6c32c2b94b0d38e8b1a1deadfdbe3bd104558ffc6fa55f265701dc262fd4f1200ea9d1802d26f5e5f79cd9859452d6128d3b3e49e36eae044c
7
- data.tar.gz: d43a9f1f2e7b0aeb0dbfd56f10a41790036f29199d1dec6862f4e97e14fd057baf72ed66a1d414073e5a590cecfbdbb0182524f486e63e4951ffa8aa11d8dfd0
6
+ metadata.gz: 8cd46477f0486ab53708fdae544736b1f7909de2cf707d63cef4c84b017bd360e4e14b4946a62b280614c29374bf063bbaee3f82171e04f7e916db6bc1ccbcec
7
+ data.tar.gz: 5d8b3303a2aa4f097ce1af9781d308a577f3fcb1054d356982ca9141b9b99cdecbdbc76315d4ed3f97a80825449a7ae06b90407a3a5cbecb282a20cbe38a42e7
@@ -76,7 +76,7 @@ The environment variables that google-cloud-firestore checks for project ID are:
76
76
  1. `FIRESTORE_PROJECT`
77
77
  2. `GOOGLE_CLOUD_PROJECT`
78
78
 
79
- The environment variables that google-cloud-firestore checks for credentials are configured on {Google::Cloud::Firestore::V1::Credentials}:
79
+ The environment variables that google-cloud-firestore checks for credentials are configured on {Google::Cloud::Firestore::Credentials}:
80
80
 
81
81
  1. `FIRESTORE_CREDENTIALS` - Path to JSON file, or JSON contents
82
82
  2. `FIRESTORE_KEYFILE` - Path to JSON file, or JSON contents
@@ -1,5 +1,60 @@
1
1
  # Release History
2
2
 
3
+ ### 2.4.0 / 2020-11-19
4
+
5
+ #### Features
6
+
7
+ * add support for != and NOT_IN queries
8
+
9
+ ### 2.3.0 / 2020-09-30
10
+
11
+ #### Features
12
+
13
+ * Add error callbacks for listener threads
14
+ * Add DocumentListener#last_error
15
+ * Add DocumentListener#on_error
16
+ * Add QueryListener#last_error
17
+ * Add QueryListener#on_error
18
+
19
+ ### 2.2.0 / 2020-09-17
20
+
21
+ #### Features
22
+
23
+ * quota_project can be set via library configuration ([#7630](https://www.github.com/googleapis/google-cloud-ruby/issues/7630))
24
+
25
+ #### Documentation
26
+
27
+ * Add snapshot query cursor sample ([#7601](https://www.github.com/googleapis/google-cloud-ruby/issues/7601))
28
+
29
+ ### 2.1.0 / 2020-09-10
30
+
31
+ #### Features
32
+
33
+ * Add Query#limit_to_last
34
+
35
+ ### 2.0.0 / 2020-08-06
36
+
37
+ This is a major update that removes the "low-level" client interface code, and
38
+ instead adds the new `google-cloud-firestore-v1` gem as a dependency.
39
+ The new dependency is a rewritten low-level client, produced by a next-
40
+ generation client code generator, with improved performance and stability.
41
+
42
+ This change should have no effect on the high-level interface that most users
43
+ will use. The one exception is that the (mostly undocumented) `client_config`
44
+ argument, for adjusting low-level parameters such as RPC retry settings on
45
+ client objects, has been removed. If you need to adjust these parameters, use
46
+ the configuration interface in `google-cloud-firestore-v1`.
47
+
48
+ Substantial changes have been made in the low-level interfaces, however. If you
49
+ are using the low-level classes under the `Google::Cloud::Firestore::V1` module,
50
+ please review the docs for the new `google-cloud-firestore-v1` gem. In
51
+ particular:
52
+
53
+ * Some classes have been renamed, notably the client class itself.
54
+ * The client constructor takes a configuration block instead of configuration
55
+ keyword arguments.
56
+ * All RPC method arguments are now keyword arguments.
57
+
3
58
  ### 1.4.4 / 2020-05-28
4
59
 
5
60
  #### Documentation
@@ -42,8 +42,6 @@ module Google
42
42
  #
43
43
  # * `https://www.googleapis.com/auth/datastore`
44
44
  # @param [Integer] timeout Default timeout to use in requests. Optional.
45
- # @param [Hash] client_config A hash of values to override the default
46
- # behavior of the API client. Optional.
47
45
  #
48
46
  # @return [Google::Cloud::Firestore::Client]
49
47
  #
@@ -60,10 +58,8 @@ module Google
60
58
  # platform_scope = "https://www.googleapis.com/auth/cloud-platform"
61
59
  # firestore = gcloud.firestore scope: platform_scope
62
60
  #
63
- def firestore scope: nil, timeout: nil, client_config: nil
64
- Google::Cloud.firestore @project, @keyfile,
65
- scope: scope, timeout: (timeout || @timeout),
66
- client_config: client_config
61
+ def firestore scope: nil, timeout: nil
62
+ Google::Cloud.firestore @project, @keyfile, scope: scope, timeout: (timeout || @timeout)
67
63
  end
68
64
 
69
65
  ##
@@ -87,8 +83,6 @@ module Google
87
83
  #
88
84
  # * `https://www.googleapis.com/auth/datastore`
89
85
  # @param [Integer] timeout Default timeout to use in requests. Optional.
90
- # @param [Hash] client_config A hash of values to override the default
91
- # behavior of the API client. Optional.
92
86
  #
93
87
  # @return [Google::Cloud::Firestore::Client]
94
88
  #
@@ -97,13 +91,12 @@ module Google
97
91
  #
98
92
  # firestore = Google::Cloud.firestore
99
93
  #
100
- def self.firestore project_id = nil, credentials = nil, scope: nil,
101
- timeout: nil, client_config: nil
94
+ def self.firestore project_id = nil, credentials = nil, scope: nil, timeout: nil
102
95
  require "google/cloud/firestore"
103
- Google::Cloud::Firestore.new project_id: project_id,
96
+ Google::Cloud::Firestore.new project_id: project_id,
104
97
  credentials: credentials,
105
- scope: scope, timeout: timeout,
106
- client_config: client_config
98
+ scope: scope,
99
+ timeout: timeout
107
100
  end
108
101
  end
109
102
  end
@@ -122,17 +115,18 @@ Google::Cloud.configure.add_config! :firestore do |config|
122
115
  default_emulator = Google::Cloud::Config.deferred do
123
116
  ENV["FIRESTORE_EMULATOR_HOST"]
124
117
  end
118
+ default_scopes = [
119
+ "https://www.googleapis.com/auth/cloud-platform",
120
+ "https://www.googleapis.com/auth/datastore"
121
+ ]
125
122
 
126
123
  config.add_field! :project_id, default_project, match: String, allow_nil: true
127
124
  config.add_alias! :project, :project_id
128
- config.add_field! :credentials, default_creds,
129
- match: [String, Hash, Google::Auth::Credentials],
130
- allow_nil: true
125
+ config.add_field! :credentials, default_creds, match: [String, Hash, Google::Auth::Credentials], allow_nil: true
131
126
  config.add_alias! :keyfile, :credentials
132
- config.add_field! :scope, nil, match: [String, Array]
127
+ config.add_field! :scope, default_scopes, match: [String, Array]
128
+ config.add_field! :quota_project, nil, match: String
133
129
  config.add_field! :timeout, nil, match: Integer
134
- config.add_field! :client_config, nil, match: Hash
135
- config.add_field! :emulator_host, default_emulator,
136
- match: String, allow_nil: true
137
- config.add_field! :endpoint, nil, match: String
130
+ config.add_field! :emulator_host, default_emulator, match: String, allow_nil: true
131
+ config.add_field! :endpoint, "firestore.googleapis.com", match: String
138
132
  end
@@ -33,7 +33,6 @@ module Google
33
33
  #
34
34
  module Firestore
35
35
  # rubocop:disable Metrics/AbcSize
36
- # rubocop:disable Metrics/MethodLength
37
36
 
38
37
  ##
39
38
  # Creates a new object for connecting to the Firestore service.
@@ -56,8 +55,6 @@ module Google
56
55
  #
57
56
  # * `https://www.googleapis.com/auth/datastore`
58
57
  # @param [Integer] timeout Default timeout to use in requests. Optional.
59
- # @param [Hash] client_config A hash of values to override the default
60
- # behavior of the API client. Optional.
61
58
  # @param [String] endpoint Override of the endpoint host name. Optional.
62
59
  # If the param is nil, uses the default endpoint.
63
60
  # @param [String] emulator_host Firestore emulator host. Optional.
@@ -73,13 +70,17 @@ module Google
73
70
  #
74
71
  # firestore = Google::Cloud::Firestore.new
75
72
  #
76
- def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil,
77
- client_config: nil, endpoint: nil, emulator_host: nil,
78
- project: nil, keyfile: nil
73
+ def self.new project_id: nil,
74
+ credentials: nil,
75
+ scope: nil,
76
+ timeout: nil,
77
+ endpoint: nil,
78
+ emulator_host: nil,
79
+ project: nil,
80
+ keyfile: nil
79
81
  project_id ||= (project || default_project_id)
80
82
  scope ||= configure.scope
81
83
  timeout ||= configure.timeout
82
- client_config ||= configure.client_config
83
84
  endpoint ||= configure.endpoint
84
85
  emulator_host ||= configure.emulator_host
85
86
 
@@ -87,13 +88,8 @@ module Google
87
88
  project_id = project_id.to_s
88
89
  raise ArgumentError, "project_id is missing" if project_id.empty?
89
90
 
90
- return Firestore::Client.new(
91
- Firestore::Service.new(
92
- project_id, :this_channel_is_insecure,
93
- host: emulator_host, timeout: timeout,
94
- client_config: client_config
95
- )
96
- )
91
+ service = Firestore::Service.new project_id, :this_channel_is_insecure, host: emulator_host, timeout: timeout
92
+ return Firestore::Client.new service
97
93
  end
98
94
 
99
95
  credentials ||= (keyfile || default_credentials(scope: scope))
@@ -107,16 +103,11 @@ module Google
107
103
  project_id = project_id.to_s
108
104
  raise ArgumentError, "project_id is missing" if project_id.empty?
109
105
 
110
- Firestore::Client.new(
111
- Firestore::Service.new(
112
- project_id, credentials,
113
- host: endpoint, timeout: timeout, client_config: client_config
114
- )
115
- )
106
+ service = Firestore::Service.new project_id, credentials, host: endpoint, timeout: timeout
107
+ Firestore::Client.new service
116
108
  end
117
109
 
118
110
  # rubocop:enable Metrics/AbcSize
119
- # rubocop:enable Metrics/MethodLength
120
111
 
121
112
  ##
122
113
  # Configure the Google Cloud Firestore library.
@@ -132,8 +123,6 @@ module Google
132
123
  # * `scope` - (String, Array<String>) The OAuth 2.0 scopes controlling
133
124
  # the set of resources and operations that the connection can access.
134
125
  # * `timeout` - (Integer) Default timeout to use in requests.
135
- # * `client_config` - (Hash) A hash of values to override the default
136
- # behavior of the API client.
137
126
  # * `endpoint` - (String) Override of the endpoint host name, or `nil`
138
127
  # to use the default endpoint.
139
128
  # * `emulator_host` - (String) Host name of the emulator. Defaults to
@@ -82,12 +82,13 @@ module Google
82
82
  # @!group Access
83
83
 
84
84
  ##
85
- # Retrieves a list of collections.
85
+ # Retrieves an enumerator for the root collections.
86
86
  #
87
87
  # @yield [collections] The block for accessing the collections.
88
- # @yieldparam [CollectionReference] collection A collection.
88
+ # @yieldparam [CollectionReference] collection A collection reference object.
89
89
  #
90
- # @return [Enumerator<CollectionReference>] collection list.
90
+ # @return [Enumerator<CollectionReference>] An enumerator of collection references. If a block is provided,
91
+ # this is the same enumerator that is accessed through the block.
91
92
  #
92
93
  # @example
93
94
  # require "google/cloud/firestore"
@@ -101,11 +102,10 @@ module Google
101
102
  #
102
103
  def cols
103
104
  ensure_service!
104
-
105
- return enum_for :cols unless block_given?
106
-
107
- collection_ids = service.list_collections "#{path}/documents"
108
- collection_ids.each { |collection_id| yield col collection_id }
105
+ grpc = service.list_collections "#{path}/documents"
106
+ cols_enum = CollectionReferenceList.from_grpc(grpc, self, "#{path}/documents").all
107
+ cols_enum.each { |c| yield c } if block_given?
108
+ cols_enum
109
109
  end
110
110
  alias collections cols
111
111
  alias list_collections cols
@@ -134,8 +134,7 @@ module Google
134
134
  raise ArgumentError, "collection_path must refer to a collection."
135
135
  end
136
136
 
137
- CollectionReference.from_path \
138
- "#{path}/documents/#{collection_path}", self
137
+ CollectionReference.from_path "#{path}/documents/#{collection_path}", self
139
138
  end
140
139
  alias collection col
141
140
 
@@ -167,9 +166,9 @@ module Google
167
166
  raise ArgumentError, "Invalid collection_id: '#{collection_id}', " \
168
167
  "must not contain '/'."
169
168
  end
170
- query = Google::Firestore::V1::StructuredQuery.new(
169
+ query = Google::Cloud::Firestore::V1::StructuredQuery.new(
171
170
  from: [
172
- Google::Firestore::V1::StructuredQuery::CollectionSelector.new(
171
+ Google::Cloud::Firestore::V1::StructuredQuery::CollectionSelector.new(
173
172
  collection_id: collection_id, all_descendants: true
174
173
  )
175
174
  ]
@@ -670,8 +669,7 @@ module Google
670
669
  # @private
671
670
  def list_documents parent, collection_id, token: nil, max: nil
672
671
  ensure_service!
673
- grpc = service.list_documents \
674
- parent, collection_id, token: token, max: max
672
+ grpc = service.list_documents parent, collection_id, token: token, max: max
675
673
  DocumentReference::List.from_grpc grpc, self, parent, collection_id
676
674
  end
677
675
 
@@ -18,6 +18,7 @@ require "google/cloud/firestore/document_reference"
18
18
  require "google/cloud/firestore/document_snapshot"
19
19
  require "google/cloud/firestore/query"
20
20
  require "google/cloud/firestore/generate"
21
+ require "google/cloud/firestore/collection_reference_list"
21
22
 
22
23
  module Google
23
24
  module Cloud
@@ -0,0 +1,137 @@
1
+ # Copyright 2020 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ require "delegate"
17
+
18
+ module Google
19
+ module Cloud
20
+ module Firestore
21
+ ##
22
+ # @private
23
+ #
24
+ # An Array delegate for pagination. Private class exposing only an Enumerator to clients.
25
+ #
26
+ class CollectionReferenceList < DelegateClass(::Array)
27
+ ##
28
+ # If not empty, indicates that there are more records that match the request and this value should be passed
29
+ # to continue.
30
+ attr_accessor :token
31
+
32
+ ##
33
+ # @private Create a new CollectionReference::List with an array of CollectionReference instances.
34
+ def initialize arr = []
35
+ super arr
36
+ end
37
+
38
+ ##
39
+ # Whether there is a next page of collection references.
40
+ #
41
+ # @return [Boolean]
42
+ #
43
+ def next?
44
+ !token.nil?
45
+ end
46
+
47
+ ##
48
+ # Retrieve the next page of collection references.
49
+ #
50
+ # @return [CollectionReference::List] The list of collection references.
51
+ #
52
+ def next
53
+ return nil unless next?
54
+ ensure_service!
55
+ grpc = @client.service.list_collections @parent, token: token, max: @max
56
+ self.class.from_grpc grpc, @client, @parent, max: @max
57
+ end
58
+
59
+ ##
60
+ # Retrieves remaining results by repeatedly invoking {#next} until {#next?} returns `false`. Calls the given
61
+ # block once for each result, which is passed as the argument to the block.
62
+ #
63
+ # An Enumerator is returned if no block is given.
64
+ #
65
+ # This method will make repeated API calls until all remaining results are retrieved. (Unlike `#each`, for
66
+ # example, which merely iterates over the results returned by a single API call.) Use with caution.
67
+ #
68
+ # @param [Integer] request_limit The upper limit of API requests to make to load all collection references.
69
+ # Default is no limit.
70
+ # @yield [collection_reference] The block for accessing each collection_reference.
71
+ # @yieldparam [CollectionReference] collection_reference The collection reference object.
72
+ #
73
+ # @return [Enumerator]
74
+ #
75
+ # @example Iterating each collection reference by passing a block:
76
+ # require "google/cloud/firestore"
77
+ #
78
+ # firestore = Google::Cloud::Firestore.new
79
+ #
80
+ # firestore.cols do |collection_reference|
81
+ # puts collection_reference.collection_id
82
+ # end
83
+ #
84
+ # @example Using the enumerator by not passing a block:
85
+ # require "google/cloud/firestore"
86
+ #
87
+ # firestore = Google::Cloud::Firestore.new
88
+ #
89
+ # all_collection_ids = firestore.cols.map do |collection_reference|
90
+ # collection_reference.collection_id
91
+ # end
92
+ #
93
+ def all request_limit: nil
94
+ request_limit = request_limit.to_i if request_limit
95
+ unless block_given?
96
+ return enum_for :all, request_limit: request_limit
97
+ end
98
+ results = self
99
+ loop do
100
+ results.each { |r| yield r }
101
+ if request_limit
102
+ request_limit -= 1
103
+ break if request_limit < 0
104
+ end
105
+ break unless results.next?
106
+ results = results.next
107
+ end
108
+ end
109
+
110
+ ##
111
+ # @private New CollectionReference::List from a `Google::Cloud::Firestore::V1::ListCollectionIdsResponse`
112
+ # object.
113
+ def self.from_grpc grpc, client, parent, max: nil
114
+ raise ArgumentError, "parent is required" unless parent
115
+ cols = CollectionReferenceList.new(Array(grpc.collection_ids).map do |collection_id|
116
+ CollectionReference.from_path "#{parent}/#{collection_id}", client
117
+ end)
118
+ token = grpc.next_page_token
119
+ token = nil if token == ""
120
+ cols.instance_variable_set :@token, token
121
+ cols.instance_variable_set :@client, client
122
+ cols.instance_variable_set :@parent, parent
123
+ cols.instance_variable_set :@max, max
124
+ cols
125
+ end
126
+
127
+ protected
128
+
129
+ ##
130
+ # Raise an error unless an active service is available.
131
+ def ensure_service!
132
+ raise "Must have active connection" unless @client.service
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end