gcloud 0.12.2 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
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,449 +0,0 @@
1
- # Copyright 2014 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 "gcloud/datastore/key"
17
- require "gcloud/datastore/properties"
18
-
19
- module Gcloud
20
- module Datastore
21
- ##
22
- # # Entity
23
- #
24
- # Entity represents a Datastore record.
25
- # Every Entity has a {Key}, and a list of properties.
26
- #
27
- # Entities in Datastore form a hierarchically structured space similar to
28
- # the directory structure of a file system. When you create an entity, you
29
- # can optionally designate another entity as its parent; the new entity is a
30
- # child of the parent entity.
31
- #
32
- # @see https://cloud.google.com/datastore/docs/concepts/entities Entities,
33
- # Properties, and Keys
34
- #
35
- # @example Create a new entity using a block:
36
- # task = datastore.entity "Task", "sampleTask" do |t|
37
- # t["type"] = "Personal"
38
- # t["created"] = Time.now
39
- # t["done"] = false
40
- # t["priority"] = 4
41
- # t["percent_complete"] = 10.0
42
- # t["description"] = "Learn Cloud Datastore"
43
- # end
44
- #
45
- # @example Create a new entity belonging to an existing parent entity:
46
- # task_key = datastore.key "Task", "sampleTask"
47
- # task_key.parent = datastore.key "TaskList", "default"
48
- #
49
- # task = Gcloud::Datastore::Entity.new
50
- # task.key = task_key
51
- #
52
- # task["type"] = "Personal"
53
- # task["done"] = false
54
- # task["priority"] = 4
55
- # task["description"] = "Learn Cloud Datastore"
56
- #
57
- class Entity
58
- ##
59
- # The Key that identifies the entity.
60
- attr_reader :key
61
-
62
- ##
63
- # Create a new Entity object.
64
- def initialize
65
- @properties = Properties.new
66
- @key = Key.new
67
- @_exclude_indexes = {}
68
- end
69
-
70
- ##
71
- # Retrieve a property value by providing the name.
72
- #
73
- # Property values are converted from the Datastore value type
74
- # automatically. Blob properties are returned as StringIO objects.
75
- # Location properties are returned as a Hash with `:longitude` and
76
- # `:latitude` keys.
77
- #
78
- # @param [String, Symbol] prop_name The name of the property.
79
- #
80
- # @return [Object, nil] Returns `nil` if the property doesn't exist
81
- #
82
- # @example Properties can be retrieved with a string name:
83
- # require "gcloud"
84
- #
85
- # gcloud = Gcloud.new
86
- # datastore = gcloud.datastore
87
- # task = datastore.find "Task", "sampleTask"
88
- # task["description"] #=> "Learn Cloud Datastore"
89
- #
90
- # @example Or with a symbol name:
91
- # require "gcloud"
92
- #
93
- # gcloud = Gcloud.new
94
- # datastore = gcloud.datastore
95
- # task = datastore.find "Task", "sampleTask"
96
- # task[:description] #=> "Learn Cloud Datastore"
97
- #
98
- # @example Getting a blob value returns a StringIO object:
99
- # require "gcloud"
100
- #
101
- # gcloud = Gcloud.new
102
- # datastore = gcloud.datastore
103
- # user = datastore.find "User", "alice"
104
- # user["avatar"] #=> StringIO("\x89PNG\r\n\x1A...")
105
- #
106
- # @example Getting a geo point value returns a Hash:
107
- # require "gcloud"
108
- #
109
- # gcloud = Gcloud.new
110
- # datastore = gcloud.datastore
111
- # user = datastore.find "User", "alice"
112
- # user["location"] #=> { longitude: -122.0862462,
113
- # # latitude: 37.4220041 }
114
- #
115
- # @example Getting a blob value returns a StringIO object:
116
- # require "gcloud"
117
- #
118
- # gcloud = Gcloud.new
119
- # datastore = gcloud.datastore
120
- # user = datastore.find "User", "alice"
121
- # user["avatar"] #=> StringIO("\x89PNG\r\n\x1A...")
122
- #
123
- def [] prop_name
124
- properties[prop_name]
125
- end
126
-
127
- ##
128
- # Set a property value by name.
129
- #
130
- # Property values are converted to use the proper Datastore value type
131
- # automatically. Use an IO-compatible object (File, StringIO, Tempfile) to
132
- # indicate the property value should be stored as a Datastore `blob`.
133
- # IO-compatible objects are converted to StringIO objects when they are
134
- # set. Use a Hash with `:longitude` and `:latitude` keys to indicate the
135
- # property value should be stored as a Geo Point/LatLng.
136
- #
137
- # @param [String, Symbol] prop_name The name of the property.
138
- # @param [Object] prop_value The value of the property.
139
- #
140
- # @example Properties can be set with a string name:
141
- # require "gcloud"
142
- #
143
- # gcloud = Gcloud.new
144
- # datastore = gcloud.datastore
145
- # task = datastore.find "Task", "sampleTask"
146
- # task["description"] = "Learn Cloud Datastore"
147
- # task["tags"] = ["fun", "programming"]
148
- #
149
- # @example Or with a symbol name:
150
- # require "gcloud"
151
- #
152
- # gcloud = Gcloud.new
153
- # datastore = gcloud.datastore
154
- # task = datastore.find "Task", "sampleTask"
155
- # task[:description] = "Learn Cloud Datastore"
156
- # task[:tags] = ["fun", "programming"]
157
- #
158
- # @example Setting a blob value using an IO:
159
- # require "gcloud"
160
- #
161
- # gcloud = Gcloud.new
162
- # datastore = gcloud.datastore
163
- # user = datastore.find "User", "alice"
164
- # user["avatar"] = File.open "/avatars/alice.png"
165
- # user["avatar"] #=> StringIO("\x89PNG\r\n\x1A...")
166
- #
167
- # @example Setting a geo point value using a Hash:
168
- # require "gcloud"
169
- #
170
- # gcloud = Gcloud.new
171
- # datastore = gcloud.datastore
172
- # user = datastore.find "User", "alice"
173
- # user["location"] = { longitude: -122.0862462, latitude: 37.4220041 }
174
- #
175
- # @example Setting a blob value using an IO:
176
- # require "gcloud"
177
- #
178
- # gcloud = Gcloud.new
179
- # datastore = gcloud.datastore
180
- # user = datastore.find "User", "alice"
181
- # user["avatar"] = File.open "/avatars/alice.png"
182
- # user["avatar"] #=> StringIO("\x89PNG\r\n\x1A...")
183
- #
184
- def []= prop_name, prop_value
185
- properties[prop_name] = prop_value
186
- end
187
-
188
- ##
189
- # Retrieve properties in a hash-like structure.
190
- # Properties can be accessed or set by string or symbol.
191
- #
192
- # @return [Gcloud::Datastore::Properties]
193
- #
194
- # @example
195
- # task.properties[:description] = "Learn Cloud Datastore"
196
- # task.properties["description"] #=> "Learn Cloud Datastore"
197
- #
198
- # task.properties.each do |name, value|
199
- # puts "property #{name} has a value of #{value}"
200
- # end
201
- #
202
- # @example A property's existence can be determined by calling `exist?`:
203
- # task.properties.exist? :description #=> true
204
- # task.properties.exist? "description" #=> true
205
- # task.properties.exist? :expiration #=> false
206
- #
207
- # @example A property can be removed from the entity:
208
- # task.properties.delete :description
209
- # task.save
210
- #
211
- # @example The properties can be converted to a hash:
212
- # prop_hash = task.properties.to_h
213
- #
214
- attr_reader :properties
215
-
216
- ##
217
- # Sets the {Gcloud::Datastore::Key} that identifies the entity.
218
- #
219
- # Once the entity is saved, the key is frozen and immutable. Trying to set
220
- # a key when immutable will raise a `RuntimeError`.
221
- #
222
- # @example The key can be set before the entity is saved:
223
- # require "gcloud"
224
- #
225
- # gcloud = Gcloud.new
226
- # datastore = gcloud.datastore
227
- # task = Gcloud::Datastore::Entity.new
228
- # task.key = datastore.key "Task"
229
- # datastore.save task
230
- #
231
- # @example Once the entity is saved, the key is frozen and immutable:
232
- # require "gcloud"
233
- #
234
- # gcloud = Gcloud.new
235
- # datastore = gcloud.datastore
236
- # task = datastore.find "Task", "sampleTask"
237
- # task.persisted? #=> true
238
- # task.key = datastore.key "Task" #=> RuntimeError
239
- # task.key.frozen? #=> true
240
- # task.key.id = 9876543221 #=> RuntimeError
241
- #
242
- def key= new_key
243
- fail "This entity's key is immutable." if persisted?
244
- @key = new_key
245
- end
246
-
247
- ##
248
- # Indicates if the record is persisted. Default is false.
249
- #
250
- # @example
251
- # require "gcloud"
252
- #
253
- # gcloud = Gcloud.new
254
- # datastore = gcloud.datastore
255
- #
256
- # task = Gcloud::Datastore::Entity.new
257
- # task.persisted? #=> false
258
- #
259
- # task = datastore.find "Task", "sampleTask"
260
- # task.persisted? #=> true
261
- #
262
- def persisted?
263
- @key && @key.frozen?
264
- end
265
-
266
- ##
267
- # Indicates if a property is flagged to be excluded from the
268
- # Datastore indexes. The default value is `false`. This is another way of
269
- # saying that values are indexed by default.
270
- #
271
- # If the property is multi-valued, each value in the list can be managed
272
- # separately for exclusion from indexing. Calling this method for a
273
- # multi-valued property will return an array that contains the `excluded`
274
- # boolean value for each corresponding value in the property. For example,
275
- # if a multi-valued property contains `["a", "b"]`, and only the value
276
- # `"b"` is indexed (meaning that `"a"`' is excluded), the return value for
277
- # this method will be `[true, false]`.
278
- #
279
- # @see https://cloud.google.com/datastore/docs/concepts/indexes#Datastore_Unindexed_properties
280
- # Unindexed properties
281
- #
282
- # @example Single property values will return a single flag setting:
283
- # task["priority"] = 4
284
- # task.exclude_from_indexes? "priority" #=> false
285
- #
286
- # @example A multi-valued property will return an array of flag settings:
287
- # task["tags"] = ["fun", "programming"]
288
- # task.exclude_from_indexes! "tags", [true, false]
289
- #
290
- # task.exclude_from_indexes? "tags" #=> [true, false]
291
- #
292
- def exclude_from_indexes? name
293
- value = self[name]
294
- flag = @_exclude_indexes[name.to_s]
295
- map_exclude_flag_to_value flag, value
296
- end
297
-
298
- ##
299
- # Sets whether a property should be excluded from the Datastore indexes.
300
- # Setting `true` will exclude the property from the indexes.
301
- # Setting `false` will include the property on any applicable indexes.
302
- # The default value is `false`. This is another way of saying that values
303
- # are indexed by default.
304
- #
305
- # If the property is multi-valued, each value in the list can be managed
306
- # separately for exclusion from indexing. When you call this method for a
307
- # multi-valued property, you can pass either a single boolean argument to
308
- # be applied to all of the values, or an array that contains the boolean
309
- # argument for each corresponding value in the property. For example,
310
- # if a multi-valued property contains `["a", "b"]`, and only the value
311
- # `"b"` should be indexed (meaning that `"a"`' should be excluded), you
312
- # should pass the array: `[true, false]`.
313
- #
314
- # @param [String] name the property name
315
- # @param [Boolean, Array<Boolean>, nil] flag whether the value or values
316
- # should be excluded from indexing
317
- # @yield [value] a block yielding each value of the property
318
- # @yieldparam [Object] value a value of the property
319
- # @yieldreturn [Boolean] `true` if the value should be excluded from
320
- # indexing
321
- #
322
- # @see https://cloud.google.com/datastore/docs/concepts/indexes#Datastore_Unindexed_properties
323
- # Unindexed properties
324
- #
325
- # @example
326
- # entity["priority"] = 4
327
- # entity.exclude_from_indexes! "priority", true
328
- #
329
- # @example Multi-valued properties can be given multiple exclude flags:
330
- # entity["tags"] = ["fun", "programming"]
331
- # entity.exclude_from_indexes! "tags", [true, false]
332
- #
333
- # @example Or, a single flag can be applied to all values in a property:
334
- # entity["tags"] = ["fun", "programming"]
335
- # entity.exclude_from_indexes! "tags", true
336
- #
337
- # @example Flags can also be set with a block:
338
- # entity["priority"] = 4
339
- # entity.exclude_from_indexes! "priority" do |priority|
340
- # priority > 4
341
- # end
342
- #
343
- def exclude_from_indexes! name, flag = nil, &block
344
- name = name.to_s
345
- flag = block if block_given?
346
- if flag.nil?
347
- @_exclude_indexes.delete name
348
- else
349
- @_exclude_indexes[name] = flag
350
- end
351
- end
352
-
353
- ##
354
- # The number of bytes the Entity will take to serialize during API calls.
355
- def serialized_size
356
- to_grpc.to_proto.length
357
- end
358
-
359
- ##
360
- # @private Convert the Entity to a Google::Datastore::V1beta3::Entity
361
- # object.
362
- def to_grpc
363
- grpc = Google::Datastore::V1beta3::Entity.new(
364
- key: @key.to_grpc,
365
- properties: @properties.to_grpc
366
- )
367
- update_properties_indexed! grpc.properties
368
- grpc
369
- end
370
-
371
- ##
372
- # @private Create a new Entity from a Google::Datastore::V1beta3::Key
373
- # object.
374
- def self.from_grpc grpc
375
- entity = Entity.new
376
- entity.key = Key.from_grpc grpc.key
377
- entity.send :properties=, Properties.from_grpc(grpc.properties)
378
- entity.send :update_exclude_indexes!, grpc.properties
379
- entity
380
- end
381
-
382
- protected
383
-
384
- ##
385
- # @private Allow friendly objects to set Properties object.
386
- attr_writer :properties
387
-
388
- # rubocop:disable all
389
- # Disabled rubocop because this is intentionally complex.
390
-
391
- ##
392
- # @private Map the exclude flag object to value.
393
- # The flag object can be a boolean, Proc, or Array.
394
- # Procs will be called and passed in the value.
395
- # This will return an array of flags for an array value.
396
- def map_exclude_flag_to_value flag, value
397
- if value.is_a? Array
398
- if flag.is_a? Proc
399
- value.map { |v| !!flag.call(v) }
400
- elsif flag.is_a? Array
401
- (flag + Array.new(value.size)).slice(0, value.size).map { |v| !!v }
402
- else
403
- value.map { |_| !!flag }
404
- end
405
- else
406
- if flag.is_a? Proc
407
- !!flag.call(value)
408
- elsif flag.is_a? Array
409
- !!flag.first
410
- else
411
- !!flag
412
- end
413
- end
414
- end
415
-
416
- ##
417
- # @private Update the exclude data after a new object is created.
418
- def update_exclude_indexes! grpc_map
419
- @_exclude_indexes = {}
420
- grpc_map.each do |name, value|
421
- next if value.nil?
422
- @_exclude_indexes[name] = value.exclude_from_indexes
423
- unless value.array_value.nil?
424
- exclude = value.array_value.values.map(&:exclude_from_indexes)
425
- @_exclude_indexes[name] = exclude
426
- end
427
- end
428
- end
429
-
430
- ##
431
- # @private Update the indexed values before the object is saved.
432
- def update_properties_indexed! grpc_map
433
- grpc_map.each do |name, value|
434
- next if value.nil?
435
- excluded = exclude_from_indexes? name
436
- if excluded.is_a? Array
437
- value.array_value.values.each_with_index do |v, i|
438
- v.exclude_from_indexes = excluded[i]
439
- end
440
- else
441
- value.exclude_from_indexes = excluded
442
- end
443
- end
444
- end
445
-
446
- # rubocop:enable all
447
- end
448
- end
449
- end
@@ -1,41 +0,0 @@
1
- # Copyright 2014 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 "gcloud/errors"
17
-
18
- module Gcloud
19
- module Datastore
20
- ##
21
- # # KeyError
22
- #
23
- # Raised when a key is not correct.
24
- class KeyError < Gcloud::Error
25
- end
26
-
27
- ##
28
- # # PropertyError
29
- #
30
- # Raised when a property is not correct.
31
- class PropertyError < Gcloud::Error
32
- end
33
-
34
- ##
35
- # # TransactionError
36
- #
37
- # General error for Transaction problems.
38
- class TransactionError < Gcloud::Error
39
- end
40
- end
41
- end