gcloud 0.12.2 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. checksums.yaml +5 -13
  2. data/lib/gcloud.rb +27 -456
  3. data/lib/gcloud/bigquery.rb +2 -382
  4. data/lib/gcloud/datastore.rb +2 -576
  5. data/lib/gcloud/dns.rb +2 -321
  6. data/lib/gcloud/logging.rb +1 -322
  7. data/lib/gcloud/pubsub.rb +2 -476
  8. data/lib/gcloud/resource_manager.rb +2 -273
  9. data/lib/gcloud/storage.rb +2 -440
  10. data/lib/gcloud/translate.rb +1 -250
  11. data/lib/gcloud/version.rb +2 -2
  12. data/lib/gcloud/vision.rb +1 -501
  13. metadata +36 -332
  14. data/AUTHENTICATION.md +0 -75
  15. data/CHANGELOG.md +0 -382
  16. data/OVERVIEW.md +0 -259
  17. data/lib/gcloud/backoff.rb +0 -150
  18. data/lib/gcloud/bigquery/copy_job.rb +0 -97
  19. data/lib/gcloud/bigquery/credentials.rb +0 -29
  20. data/lib/gcloud/bigquery/data.rb +0 -239
  21. data/lib/gcloud/bigquery/dataset.rb +0 -753
  22. data/lib/gcloud/bigquery/dataset/access.rb +0 -507
  23. data/lib/gcloud/bigquery/dataset/list.rb +0 -169
  24. data/lib/gcloud/bigquery/extract_job.rb +0 -117
  25. data/lib/gcloud/bigquery/insert_response.rb +0 -81
  26. data/lib/gcloud/bigquery/job.rb +0 -299
  27. data/lib/gcloud/bigquery/job/list.rb +0 -172
  28. data/lib/gcloud/bigquery/load_job.rb +0 -202
  29. data/lib/gcloud/bigquery/project.rb +0 -475
  30. data/lib/gcloud/bigquery/query_data.rb +0 -234
  31. data/lib/gcloud/bigquery/query_job.rb +0 -137
  32. data/lib/gcloud/bigquery/schema.rb +0 -359
  33. data/lib/gcloud/bigquery/service.rb +0 -506
  34. data/lib/gcloud/bigquery/table.rb +0 -1141
  35. data/lib/gcloud/bigquery/table/list.rb +0 -180
  36. data/lib/gcloud/bigquery/view.rb +0 -475
  37. data/lib/gcloud/credentials.rb +0 -129
  38. data/lib/gcloud/datastore/commit.rb +0 -148
  39. data/lib/gcloud/datastore/credentials.rb +0 -35
  40. data/lib/gcloud/datastore/cursor.rb +0 -76
  41. data/lib/gcloud/datastore/dataset.rb +0 -660
  42. data/lib/gcloud/datastore/dataset/lookup_results.rb +0 -219
  43. data/lib/gcloud/datastore/dataset/query_results.rb +0 -386
  44. data/lib/gcloud/datastore/entity.rb +0 -449
  45. data/lib/gcloud/datastore/errors.rb +0 -41
  46. data/lib/gcloud/datastore/gql_query.rb +0 -211
  47. data/lib/gcloud/datastore/grpc_utils.rb +0 -132
  48. data/lib/gcloud/datastore/key.rb +0 -281
  49. data/lib/gcloud/datastore/properties.rb +0 -128
  50. data/lib/gcloud/datastore/query.rb +0 -348
  51. data/lib/gcloud/datastore/service.rb +0 -167
  52. data/lib/gcloud/datastore/transaction.rb +0 -362
  53. data/lib/gcloud/dns/change.rb +0 -158
  54. data/lib/gcloud/dns/change/list.rb +0 -173
  55. data/lib/gcloud/dns/credentials.rb +0 -29
  56. data/lib/gcloud/dns/importer.rb +0 -183
  57. data/lib/gcloud/dns/project.rb +0 -247
  58. data/lib/gcloud/dns/record.rb +0 -170
  59. data/lib/gcloud/dns/record/list.rb +0 -174
  60. data/lib/gcloud/dns/service.rb +0 -167
  61. data/lib/gcloud/dns/zone.rb +0 -759
  62. data/lib/gcloud/dns/zone/list.rb +0 -168
  63. data/lib/gcloud/dns/zone/transaction.rb +0 -176
  64. data/lib/gcloud/errors.rb +0 -206
  65. data/lib/gcloud/gce.rb +0 -56
  66. data/lib/gcloud/grpc_utils.rb +0 -87
  67. data/lib/gcloud/logging/credentials.rb +0 -29
  68. data/lib/gcloud/logging/entry.rb +0 -465
  69. data/lib/gcloud/logging/entry/http_request.rb +0 -141
  70. data/lib/gcloud/logging/entry/list.rb +0 -177
  71. data/lib/gcloud/logging/entry/operation.rb +0 -90
  72. data/lib/gcloud/logging/logger.rb +0 -307
  73. data/lib/gcloud/logging/metric.rb +0 -169
  74. data/lib/gcloud/logging/metric/list.rb +0 -172
  75. data/lib/gcloud/logging/project.rb +0 -642
  76. data/lib/gcloud/logging/resource.rb +0 -84
  77. data/lib/gcloud/logging/resource_descriptor.rb +0 -137
  78. data/lib/gcloud/logging/resource_descriptor/list.rb +0 -174
  79. data/lib/gcloud/logging/service.rb +0 -267
  80. data/lib/gcloud/logging/sink.rb +0 -227
  81. data/lib/gcloud/logging/sink/list.rb +0 -171
  82. data/lib/gcloud/pubsub/credentials.rb +0 -29
  83. data/lib/gcloud/pubsub/message.rb +0 -94
  84. data/lib/gcloud/pubsub/policy.rb +0 -204
  85. data/lib/gcloud/pubsub/project.rb +0 -482
  86. data/lib/gcloud/pubsub/received_message.rb +0 -160
  87. data/lib/gcloud/pubsub/service.rb +0 -334
  88. data/lib/gcloud/pubsub/subscription.rb +0 -565
  89. data/lib/gcloud/pubsub/subscription/list.rb +0 -208
  90. data/lib/gcloud/pubsub/topic.rb +0 -511
  91. data/lib/gcloud/pubsub/topic/list.rb +0 -174
  92. data/lib/gcloud/pubsub/topic/publisher.rb +0 -85
  93. data/lib/gcloud/resource_manager/credentials.rb +0 -30
  94. data/lib/gcloud/resource_manager/manager.rb +0 -266
  95. data/lib/gcloud/resource_manager/policy.rb +0 -211
  96. data/lib/gcloud/resource_manager/project.rb +0 -484
  97. data/lib/gcloud/resource_manager/project/list.rb +0 -167
  98. data/lib/gcloud/resource_manager/project/updater.rb +0 -130
  99. data/lib/gcloud/resource_manager/service.rb +0 -127
  100. data/lib/gcloud/storage/bucket.rb +0 -775
  101. data/lib/gcloud/storage/bucket/acl.rb +0 -810
  102. data/lib/gcloud/storage/bucket/cors.rb +0 -153
  103. data/lib/gcloud/storage/bucket/list.rb +0 -172
  104. data/lib/gcloud/storage/credentials.rb +0 -29
  105. data/lib/gcloud/storage/errors.rb +0 -65
  106. data/lib/gcloud/storage/file.rb +0 -842
  107. data/lib/gcloud/storage/file/acl.rb +0 -425
  108. data/lib/gcloud/storage/file/list.rb +0 -191
  109. data/lib/gcloud/storage/file/verifier.rb +0 -67
  110. data/lib/gcloud/storage/project.rb +0 -316
  111. data/lib/gcloud/storage/service.rb +0 -347
  112. data/lib/gcloud/translate/api.rb +0 -241
  113. data/lib/gcloud/translate/detection.rb +0 -137
  114. data/lib/gcloud/translate/language.rb +0 -69
  115. data/lib/gcloud/translate/service.rb +0 -80
  116. data/lib/gcloud/translate/translation.rb +0 -112
  117. data/lib/gcloud/vision/annotate.rb +0 -224
  118. data/lib/gcloud/vision/annotation.rb +0 -455
  119. data/lib/gcloud/vision/annotation/entity.rb +0 -234
  120. data/lib/gcloud/vision/annotation/face.rb +0 -1750
  121. data/lib/gcloud/vision/annotation/properties.rb +0 -245
  122. data/lib/gcloud/vision/annotation/safe_search.rb +0 -161
  123. data/lib/gcloud/vision/annotation/text.rb +0 -236
  124. data/lib/gcloud/vision/annotation/vertex.rb +0 -108
  125. data/lib/gcloud/vision/credentials.rb +0 -29
  126. data/lib/gcloud/vision/image.rb +0 -590
  127. data/lib/gcloud/vision/location.rb +0 -115
  128. data/lib/gcloud/vision/project.rb +0 -278
  129. data/lib/gcloud/vision/service.rb +0 -66
  130. data/lib/google/api/annotations.rb +0 -14
  131. data/lib/google/api/http.rb +0 -30
  132. data/lib/google/api/label.rb +0 -24
  133. data/lib/google/api/monitored_resource.rb +0 -25
  134. data/lib/google/datastore/v1beta3/datastore.rb +0 -115
  135. data/lib/google/datastore/v1beta3/datastore_services.rb +0 -33
  136. data/lib/google/datastore/v1beta3/entity.rb +0 -63
  137. data/lib/google/datastore/v1beta3/query.rb +0 -128
  138. data/lib/google/devtools/cloudtrace/v1/trace.rb +0 -78
  139. data/lib/google/devtools/cloudtrace/v1/trace_services.rb +0 -32
  140. data/lib/google/example/library/v1/library.rb +0 -91
  141. data/lib/google/example/library/v1/library_services.rb +0 -40
  142. data/lib/google/iam/v1/iam_policy.rb +0 -33
  143. data/lib/google/iam/v1/iam_policy_services.rb +0 -30
  144. data/lib/google/iam/v1/policy.rb +0 -25
  145. data/lib/google/logging/type/http_request.rb +0 -28
  146. data/lib/google/logging/type/log_severity.rb +0 -27
  147. data/lib/google/logging/v2/log_entry.rb +0 -44
  148. data/lib/google/logging/v2/logging.rb +0 -56
  149. data/lib/google/logging/v2/logging_config.rb +0 -59
  150. data/lib/google/logging/v2/logging_config_services.rb +0 -32
  151. data/lib/google/logging/v2/logging_metrics.rb +0 -51
  152. data/lib/google/logging/v2/logging_metrics_services.rb +0 -32
  153. data/lib/google/logging/v2/logging_services.rb +0 -31
  154. data/lib/google/longrunning/operations.rb +0 -50
  155. data/lib/google/longrunning/operations_services.rb +0 -29
  156. data/lib/google/protobuf/descriptor.rb +0 -0
  157. data/lib/google/pubsub/v1/pubsub.rb +0 -129
  158. data/lib/google/pubsub/v1/pubsub_services.rb +0 -56
  159. data/lib/google/pubsub/v1beta2/pubsub.rb +0 -126
  160. data/lib/google/pubsub/v1beta2/pubsub_services.rb +0 -56
  161. data/lib/google/rpc/code.rb +0 -32
  162. data/lib/google/rpc/error_details.rb +0 -61
  163. data/lib/google/rpc/status.rb +0 -19
  164. data/lib/google/type/color.rb +0 -20
  165. data/lib/google/type/date.rb +0 -18
  166. data/lib/google/type/dayofweek.rb +0 -23
  167. data/lib/google/type/latlng.rb +0 -17
  168. data/lib/google/type/money.rb +0 -18
  169. data/lib/google/type/timeofday.rb +0 -19
@@ -1,425 +0,0 @@
1
- # Copyright 2015 Google Inc. All rights reserved.
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
- # http://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
- module Gcloud
17
- module Storage
18
- class File
19
- ##
20
- # # File Access Control List
21
- #
22
- # Represents a File's Access Control List.
23
- #
24
- # @example
25
- # require "gcloud"
26
- #
27
- # gcloud = Gcloud.new
28
- # storage = gcloud.storage
29
- #
30
- # bucket = storage.bucket "my-bucket"
31
- #
32
- # file = bucket.file "path/to/my-file.ext"
33
- # file.acl.readers.each { |reader| puts reader }
34
- #
35
- class Acl
36
- # @private
37
- RULES = { "authenticatedRead" => "authenticatedRead",
38
- "auth" => "authenticatedRead",
39
- "auth_read" => "authenticatedRead",
40
- "authenticated" => "authenticatedRead",
41
- "authenticated_read" => "authenticatedRead",
42
- "bucketOwnerFullControl" => "bucketOwnerFullControl",
43
- "owner_full" => "bucketOwnerFullControl",
44
- "bucketOwnerRead" => "bucketOwnerRead",
45
- "owner_read" => "bucketOwnerRead",
46
- "private" => "private",
47
- "projectPrivate" => "projectPrivate",
48
- "project_private" => "projectPrivate",
49
- "publicRead" => "publicRead",
50
- "public" => "publicRead",
51
- "public_read" => "publicRead" }
52
-
53
- ##
54
- # @private Initialized a new Acl object.
55
- # Must provide a valid Bucket object.
56
- def initialize file
57
- @bucket = file.bucket
58
- @file = file.name
59
- @service = file.service
60
- @owners = nil
61
- @readers = nil
62
- end
63
-
64
- ##
65
- # Reloads all Access Control List data for the file.
66
- #
67
- # @example
68
- # require "gcloud"
69
- #
70
- # gcloud = Gcloud.new
71
- # storage = gcloud.storage
72
- #
73
- # bucket = storage.bucket "my-bucket"
74
- #
75
- # file = bucket.file "path/to/my-file.ext"
76
- # file.acl.reload!
77
- #
78
- def reload!
79
- gapi = @service.list_file_acls @bucket, @file
80
- acls = Array(gapi.items).map do |acl|
81
- return acl if acl.is_a? Google::Apis::StorageV1::ObjectAccessControl
82
- fail "Unknown ACL format: #{acl.class}" unless acl.is_a? Hash
83
- Google::Apis::StorageV1::ObjectAccessControl.from_json acl.to_json
84
- end
85
- @owners = entities_from_acls acls, "OWNER"
86
- @readers = entities_from_acls acls, "READER"
87
- end
88
- alias_method :refresh!, :reload!
89
-
90
- ##
91
- # Lists the owners of the file.
92
- #
93
- # @return [Array<String>]
94
- #
95
- # @example
96
- # require "gcloud"
97
- #
98
- # gcloud = Gcloud.new
99
- # storage = gcloud.storage
100
- #
101
- # bucket = storage.bucket "my-bucket"
102
- #
103
- # file = bucket.file "path/to/my-file.ext"
104
- # file.acl.owners.each { |owner| puts owner }
105
- #
106
- def owners
107
- reload! if @owners.nil?
108
- @owners
109
- end
110
-
111
- ##
112
- # Lists the readers of the file.
113
- #
114
- # @return [Array<String>]
115
- #
116
- # @example
117
- # require "gcloud"
118
- #
119
- # gcloud = Gcloud.new
120
- # storage = gcloud.storage
121
- #
122
- # bucket = storage.bucket "my-bucket"
123
- #
124
- # file = bucket.file "path/to/my-file.ext"
125
- # file.acl.readers.each { |reader| puts reader }
126
- #
127
- def readers
128
- reload! if @readers.nil?
129
- @readers
130
- end
131
-
132
- ##
133
- # Grants owner permission to the file.
134
- #
135
- # @param [String] entity The entity holding the permission, in one of
136
- # the following forms:
137
- #
138
- # * user-userId
139
- # * user-email
140
- # * group-groupId
141
- # * group-email
142
- # * domain-domain
143
- # * project-team-projectId
144
- # * allUsers
145
- # * allAuthenticatedUsers
146
- #
147
- # @param [Integer] generation When present, selects a specific revision
148
- # of this object. Default is the latest version.
149
- #
150
- # @example Grant access to a user by pre-pending `"user-"` to an email:
151
- # require "gcloud"
152
- #
153
- # gcloud = Gcloud.new
154
- # storage = gcloud.storage
155
- #
156
- # bucket = storage.bucket "my-bucket"
157
- #
158
- # file = bucket.file "path/to/my-file.ext"
159
- # email = "heidi@example.net"
160
- # file.acl.add_owner "user-#{email}"
161
- #
162
- # @example Grant access to a group by pre-pending `"group-"` to an email
163
- # require "gcloud"
164
- #
165
- # gcloud = Gcloud.new
166
- # storage = gcloud.storage
167
- #
168
- # bucket = storage.bucket "my-bucket"
169
- #
170
- # file = bucket.file "path/to/my-file.ext"
171
- # email = "authors@example.net"
172
- # file.acl.add_owner "group-#{email}"
173
- #
174
- def add_owner entity, generation: nil
175
- options = { generation: generation }
176
- gapi = @service.insert_file_acl @bucket, @file, entity, "OWNER",
177
- options
178
- entity = gapi.entity
179
- @owners.push entity unless @owners.nil?
180
- entity
181
- end
182
-
183
- ##
184
- # Grants reader permission to the file.
185
- #
186
- # @param [String] entity The entity holding the permission, in one of
187
- # the following forms:
188
- #
189
- # * user-userId
190
- # * user-email
191
- # * group-groupId
192
- # * group-email
193
- # * domain-domain
194
- # * project-team-projectId
195
- # * allUsers
196
- # * allAuthenticatedUsers
197
- #
198
- # @param [Integer] generation When present, selects a specific revision
199
- # of this object. Default is the latest version.
200
- #
201
- # @example Grant access to a user by pre-pending `"user-"` to an email:
202
- # require "gcloud"
203
- #
204
- # gcloud = Gcloud.new
205
- # storage = gcloud.storage
206
- #
207
- # bucket = storage.bucket "my-bucket"
208
- #
209
- # file = bucket.file "path/to/my-file.ext"
210
- # email = "heidi@example.net"
211
- # file.acl.add_reader "user-#{email}"
212
- #
213
- # @example Grant access to a group by pre-pending `"group-"` to an email
214
- # require "gcloud"
215
- #
216
- # gcloud = Gcloud.new
217
- # storage = gcloud.storage
218
- #
219
- # bucket = storage.bucket "my-bucket"
220
- #
221
- # file = bucket.file "path/to/my-file.ext"
222
- # email = "authors@example.net"
223
- # file.acl.add_reader "group-#{email}"
224
- #
225
- def add_reader entity, generation: nil
226
- options = { generation: generation }
227
- gapi = @service.insert_file_acl @bucket, @file, entity, "READER",
228
- options
229
- entity = gapi.entity
230
- @readers.push entity unless @readers.nil?
231
- entity
232
- end
233
-
234
- ##
235
- # Permanently deletes the entity from the file's access control list.
236
- #
237
- # @param [String] entity The entity holding the permission, in one of
238
- # the following forms:
239
- #
240
- # * user-userId
241
- # * user-email
242
- # * group-groupId
243
- # * group-email
244
- # * domain-domain
245
- # * project-team-projectId
246
- # * allUsers
247
- # * allAuthenticatedUsers
248
- #
249
- # @param [Integer] generation When present, selects a specific revision
250
- # of this object. Default is the latest version.
251
- #
252
- # @example
253
- # require "gcloud"
254
- #
255
- # gcloud = Gcloud.new
256
- # storage = gcloud.storage
257
- #
258
- # bucket = storage.bucket "my-bucket"
259
- #
260
- # file = bucket.file "path/to/my-file.ext"
261
- # email = "heidi@example.net"
262
- # file.acl.delete "user-#{email}"
263
- #
264
- def delete entity, generation: nil
265
- options = { generation: generation }
266
- @service.delete_file_acl @bucket, @file, entity, options
267
- @owners.delete entity unless @owners.nil?
268
- @readers.delete entity unless @readers.nil?
269
- true
270
- end
271
-
272
- # @private
273
- def self.predefined_rule_for rule_name
274
- RULES[rule_name.to_s]
275
- end
276
-
277
- # Predefined ACL helpers
278
-
279
- ##
280
- # Convenience method to apply the `authenticatedRead` predefined ACL
281
- # rule to the file.
282
- #
283
- # @example
284
- # require "gcloud"
285
- #
286
- # gcloud = Gcloud.new
287
- # storage = gcloud.storage
288
- #
289
- # bucket = storage.bucket "my-bucket"
290
- #
291
- # file = bucket.file "path/to/my-file.ext"
292
- # file.acl.auth!
293
- #
294
- def auth!
295
- update_predefined_acl! "authenticatedRead"
296
- end
297
- alias_method :authenticatedRead!, :auth!
298
- alias_method :auth_read!, :auth!
299
- alias_method :authenticated!, :auth!
300
- alias_method :authenticated_read!, :auth!
301
-
302
- ##
303
- # Convenience method to apply the `bucketOwnerFullControl` predefined
304
- # ACL rule to the file.
305
- #
306
- # @example
307
- # require "gcloud"
308
- #
309
- # gcloud = Gcloud.new
310
- # storage = gcloud.storage
311
- #
312
- # bucket = storage.bucket "my-bucket"
313
- #
314
- # file = bucket.file "path/to/my-file.ext"
315
- # file.acl.owner_full!
316
- #
317
- def owner_full!
318
- update_predefined_acl! "bucketOwnerFullControl"
319
- end
320
- alias_method :bucketOwnerFullControl!, :owner_full!
321
-
322
- ##
323
- # Convenience method to apply the `bucketOwnerRead` predefined ACL
324
- # rule to the file.
325
- #
326
- # @example
327
- # require "gcloud"
328
- #
329
- # gcloud = Gcloud.new
330
- # storage = gcloud.storage
331
- #
332
- # bucket = storage.bucket "my-bucket"
333
- #
334
- # file = bucket.file "path/to/my-file.ext"
335
- # file.acl.owner_read!
336
- #
337
- def owner_read!
338
- update_predefined_acl! "bucketOwnerRead"
339
- end
340
- alias_method :bucketOwnerRead!, :owner_read!
341
-
342
- ##
343
- # Convenience method to apply the `private` predefined ACL
344
- # rule to the file.
345
- #
346
- # @example
347
- # require "gcloud"
348
- #
349
- # gcloud = Gcloud.new
350
- # storage = gcloud.storage
351
- #
352
- # bucket = storage.bucket "my-bucket"
353
- #
354
- # file = bucket.file "path/to/my-file.ext"
355
- # file.acl.private!
356
- #
357
- def private!
358
- update_predefined_acl! "private"
359
- end
360
-
361
- ##
362
- # Convenience method to apply the `projectPrivate` predefined ACL
363
- # rule to the file.
364
- #
365
- # @example
366
- # require "gcloud"
367
- #
368
- # gcloud = Gcloud.new
369
- # storage = gcloud.storage
370
- #
371
- # bucket = storage.bucket "my-bucket"
372
- #
373
- # file = bucket.file "path/to/my-file.ext"
374
- # file.acl.project_private!
375
- #
376
- def project_private!
377
- update_predefined_acl! "projectPrivate"
378
- end
379
- alias_method :projectPrivate!, :project_private!
380
-
381
- ##
382
- # Convenience method to apply the `publicRead` predefined ACL
383
- # rule to the file.
384
- #
385
- # @example
386
- # require "gcloud"
387
- #
388
- # gcloud = Gcloud.new
389
- # storage = gcloud.storage
390
- #
391
- # bucket = storage.bucket "my-bucket"
392
- #
393
- # file = bucket.file "path/to/my-file.ext"
394
- # file.acl.public!
395
- #
396
- def public!
397
- update_predefined_acl! "publicRead"
398
- end
399
- alias_method :publicRead!, :public!
400
- alias_method :public_read!, :public!
401
-
402
- protected
403
-
404
- def clear!
405
- @owners = nil
406
- @readers = nil
407
- self
408
- end
409
-
410
- def update_predefined_acl! acl_role
411
- patched_file = Google::Apis::StorageV1::Object.new acl: nil
412
- @service.patch_file \
413
- @bucket, @file, patched_file, predefined_acl: acl_role
414
- clear!
415
- end
416
-
417
- def entities_from_acls acls, role
418
- selected = acls.select { |acl| acl.role == role }
419
- entities = selected.map(&:entity)
420
- entities
421
- end
422
- end
423
- end
424
- end
425
- end
@@ -1,191 +0,0 @@
1
- # Copyright 2015 Google Inc. All rights reserved.
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
- # http://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 Gcloud
19
- module Storage
20
- class File
21
- ##
22
- # File::List is a special case Array with additional values.
23
- class List < DelegateClass(::Array)
24
- ##
25
- # If not empty, indicates that there are more files that match the
26
- # request and this value should be passed to the next
27
- # {Gcloud::Storage::Bucket#files} to continue.
28
- attr_accessor :token
29
-
30
- # The list of prefixes of objects matching-but-not-listed up to and
31
- # including the requested delimiter.
32
- attr_accessor :prefixes
33
-
34
- ##
35
- # @private Create a new File::List with an array of values.
36
- def initialize arr = []
37
- super arr
38
- end
39
-
40
- ##
41
- # Whether there is a next page of files.
42
- #
43
- # @return [Boolean]
44
- #
45
- # @example
46
- # require "gcloud"
47
- #
48
- # gcloud = Gcloud.new
49
- # storage = gcloud.storage
50
- #
51
- # bucket = storage.bucket "my-bucket"
52
- # files = bucket.files
53
- # if files.next?
54
- # next_files = files.next
55
- # end
56
- #
57
- def next?
58
- !token.nil?
59
- end
60
-
61
- ##
62
- # Retrieve the next page of files.
63
- #
64
- # @return [File::List]
65
- #
66
- # @example
67
- # require "gcloud"
68
- #
69
- # gcloud = Gcloud.new
70
- # storage = gcloud.storage
71
- #
72
- # bucket = storage.bucket "my-bucket"
73
- # files = bucket.files
74
- # if files.next?
75
- # next_files = files.next
76
- # end
77
- #
78
- def next
79
- return nil unless next?
80
- ensure_service!
81
- options = {
82
- prefix: @prefix, delimiter: @delimiter, token: @token, max: @max,
83
- versions: @versions
84
- }
85
- gapi = @service.list_files @bucket, options
86
- File::List.from_gapi gapi, @service, @bucket, @prefix,
87
- @delimiter, @max, @versions
88
- end
89
-
90
- ##
91
- # Retrieves all files by repeatedly loading {#next} until {#next?}
92
- # returns `false`. Calls the given block once for each file, which is
93
- # passed as the parameter.
94
- #
95
- # An Enumerator is returned if no block is given.
96
- #
97
- # This method may make several API calls until all files are retrieved.
98
- # Be sure to use as narrow a search criteria as possible. Please use
99
- # with caution.
100
- #
101
- # @param [Integer] request_limit The upper limit of API requests to make
102
- # to load all files. Default is no limit.
103
- # @yield [file] The block for accessing each file.
104
- # @yieldparam [File] file The file object.
105
- #
106
- # @return [Enumerator]
107
- #
108
- # @example Iterating each file by passing a block:
109
- # require "gcloud"
110
- #
111
- # gcloud = Gcloud.new
112
- # storage = gcloud.storage
113
- #
114
- # bucket = storage.bucket "my-bucket"
115
- # files = bucket.files
116
- # files.all do |file|
117
- # puts file.name
118
- # end
119
- #
120
- # @example Using the enumerator by not passing a block:
121
- # require "gcloud"
122
- #
123
- # gcloud = Gcloud.new
124
- # storage = gcloud.storage
125
- #
126
- # bucket = storage.bucket "my-bucket"
127
- # files = bucket.files
128
- #
129
- # all_names = files.all.map do |file|
130
- # file.name
131
- # end
132
- #
133
- # @example Limit the number of API calls made:
134
- # require "gcloud"
135
- #
136
- # gcloud = Gcloud.new
137
- # storage = gcloud.storage
138
- #
139
- # bucket = storage.bucket "my-bucket"
140
- # files = bucket.files
141
- # files.all(request_limit: 10) do |file|
142
- # puts file.name
143
- # end
144
- #
145
- def all request_limit: nil
146
- request_limit = request_limit.to_i if request_limit
147
- unless block_given?
148
- return enum_for(:all, request_limit: request_limit)
149
- end
150
- results = self
151
- loop do
152
- results.each { |r| yield r }
153
- if request_limit
154
- request_limit -= 1
155
- break if request_limit < 0
156
- end
157
- break unless results.next?
158
- results = results.next
159
- end
160
- end
161
-
162
- ##
163
- # @private New File::List from a Google API Client
164
- # Google::Apis::StorageV1::Objects object.
165
- def self.from_gapi gapi_list, service, bucket = nil, prefix = nil,
166
- delimiter = nil, max = nil, versions = nil
167
- files = new(Array(gapi_list.items).map do |gapi_object|
168
- File.from_gapi gapi_object, service
169
- end)
170
- files.instance_variable_set :@token, gapi_list.next_page_token
171
- files.instance_variable_set :@prefixes, Array(gapi_list.prefixes)
172
- files.instance_variable_set :@service, service
173
- files.instance_variable_set :@bucket, bucket
174
- files.instance_variable_set :@prefix, prefix
175
- files.instance_variable_set :@delimiter, delimiter
176
- files.instance_variable_set :@max, max
177
- files.instance_variable_set :@versions, versions
178
- files
179
- end
180
-
181
- protected
182
-
183
- ##
184
- # Raise an error unless an active service is available.
185
- def ensure_service!
186
- fail "Must have active connection" unless @service
187
- end
188
- end
189
- end
190
- end
191
- end