gcloud 0.6.3 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/AUTHENTICATION.md +13 -9
- data/CHANGELOG.md +8 -3
- data/OVERVIEW.md +46 -8
- data/lib/gcloud.rb +123 -117
- data/lib/gcloud/backoff.rb +43 -15
- data/lib/gcloud/bigquery.rb +211 -195
- data/lib/gcloud/bigquery/connection.rb +9 -9
- data/lib/gcloud/bigquery/copy_job.rb +15 -16
- data/lib/gcloud/bigquery/credentials.rb +3 -3
- data/lib/gcloud/bigquery/data.rb +12 -11
- data/lib/gcloud/bigquery/dataset.rb +162 -216
- data/lib/gcloud/bigquery/dataset/access.rb +59 -43
- data/lib/gcloud/bigquery/dataset/list.rb +3 -3
- data/lib/gcloud/bigquery/errors.rb +9 -5
- data/lib/gcloud/bigquery/extract_job.rb +18 -18
- data/lib/gcloud/bigquery/insert_response.rb +7 -4
- data/lib/gcloud/bigquery/job.rb +48 -44
- data/lib/gcloud/bigquery/job/list.rb +3 -3
- data/lib/gcloud/bigquery/load_job.rb +24 -25
- data/lib/gcloud/bigquery/project.rb +145 -204
- data/lib/gcloud/bigquery/query_data.rb +10 -9
- data/lib/gcloud/bigquery/query_job.rb +23 -32
- data/lib/gcloud/bigquery/table.rb +238 -280
- data/lib/gcloud/bigquery/table/list.rb +3 -3
- data/lib/gcloud/bigquery/table/schema.rb +79 -87
- data/lib/gcloud/bigquery/view.rb +69 -82
- data/lib/gcloud/credentials.rb +3 -9
- data/lib/gcloud/datastore.rb +194 -170
- data/lib/gcloud/datastore/connection.rb +12 -8
- data/lib/gcloud/datastore/credentials.rb +6 -4
- data/lib/gcloud/datastore/dataset.rb +74 -141
- data/lib/gcloud/datastore/dataset/lookup_results.rb +6 -4
- data/lib/gcloud/datastore/dataset/query_results.rb +6 -4
- data/lib/gcloud/datastore/entity.rb +81 -76
- data/lib/gcloud/datastore/errors.rb +10 -8
- data/lib/gcloud/datastore/key.rb +41 -77
- data/lib/gcloud/datastore/properties.rb +3 -3
- data/lib/gcloud/datastore/proto.rb +7 -4
- data/lib/gcloud/datastore/query.rb +26 -3
- data/lib/gcloud/datastore/transaction.rb +12 -8
- data/lib/gcloud/dns.rb +180 -152
- data/lib/gcloud/dns/change.rb +16 -16
- data/lib/gcloud/dns/change/list.rb +3 -3
- data/lib/gcloud/dns/connection.rb +9 -10
- data/lib/gcloud/dns/credentials.rb +3 -3
- data/lib/gcloud/dns/errors.rb +9 -5
- data/lib/gcloud/dns/importer.rb +17 -23
- data/lib/gcloud/dns/project.rb +42 -64
- data/lib/gcloud/dns/record.rb +58 -46
- data/lib/gcloud/dns/record/list.rb +6 -7
- data/lib/gcloud/dns/zone.rb +198 -289
- data/lib/gcloud/dns/zone/list.rb +3 -3
- data/lib/gcloud/dns/zone/transaction.rb +56 -72
- data/lib/gcloud/errors.rb +174 -3
- data/lib/gcloud/gce.rb +3 -4
- data/lib/gcloud/grpc_utils.rb +76 -0
- data/lib/gcloud/logging.rb +308 -0
- data/lib/gcloud/logging/credentials.rb +29 -0
- data/lib/gcloud/logging/entry.rb +303 -0
- data/lib/gcloud/logging/entry/http_request.rb +141 -0
- data/lib/gcloud/logging/entry/list.rb +111 -0
- data/lib/gcloud/logging/entry/operation.rb +90 -0
- data/lib/gcloud/logging/logger.rb +307 -0
- data/lib/gcloud/logging/metric.rb +175 -0
- data/lib/gcloud/logging/metric/list.rb +98 -0
- data/lib/gcloud/logging/project.rb +650 -0
- data/lib/gcloud/logging/resource.rb +95 -0
- data/lib/gcloud/logging/resource_descriptor.rb +140 -0
- data/lib/gcloud/logging/resource_descriptor/list.rb +78 -0
- data/lib/gcloud/logging/service.rb +258 -0
- data/lib/gcloud/logging/sink.rb +233 -0
- data/lib/gcloud/logging/sink/list.rb +97 -0
- data/lib/gcloud/pubsub.rb +241 -199
- data/lib/gcloud/pubsub/credentials.rb +3 -3
- data/lib/gcloud/pubsub/message.rb +26 -20
- data/lib/gcloud/pubsub/project.rb +166 -233
- data/lib/gcloud/pubsub/received_message.rb +28 -38
- data/lib/gcloud/pubsub/service.rb +323 -0
- data/lib/gcloud/pubsub/subscription.rb +172 -242
- data/lib/gcloud/pubsub/subscription/list.rb +11 -9
- data/lib/gcloud/pubsub/topic.rb +152 -271
- data/lib/gcloud/pubsub/topic/batch.rb +66 -0
- data/lib/gcloud/pubsub/topic/list.rb +9 -7
- data/lib/gcloud/resource_manager.rb +158 -138
- data/lib/gcloud/resource_manager/connection.rb +6 -5
- data/lib/gcloud/resource_manager/credentials.rb +3 -3
- data/lib/gcloud/resource_manager/errors.rb +9 -5
- data/lib/gcloud/resource_manager/manager.rb +54 -86
- data/lib/gcloud/resource_manager/project.rb +69 -88
- data/lib/gcloud/resource_manager/project/list.rb +4 -5
- data/lib/gcloud/resource_manager/project/updater.rb +12 -14
- data/lib/gcloud/search.rb +158 -135
- data/lib/gcloud/search/api_client.rb +7 -7
- data/lib/gcloud/search/connection.rb +8 -8
- data/lib/gcloud/search/credentials.rb +3 -3
- data/lib/gcloud/search/document.rb +64 -87
- data/lib/gcloud/search/document/list.rb +5 -5
- data/lib/gcloud/search/errors.rb +9 -5
- data/lib/gcloud/search/field_value.rb +32 -38
- data/lib/gcloud/search/field_values.rb +50 -80
- data/lib/gcloud/search/fields.rb +44 -65
- data/lib/gcloud/search/index.rb +163 -204
- data/lib/gcloud/search/index/list.rb +5 -5
- data/lib/gcloud/search/project.rb +31 -47
- data/lib/gcloud/search/result.rb +27 -31
- data/lib/gcloud/search/result/list.rb +6 -6
- data/lib/gcloud/storage.rb +224 -190
- data/lib/gcloud/storage/bucket.rb +202 -227
- data/lib/gcloud/storage/bucket/acl.rb +83 -170
- data/lib/gcloud/storage/bucket/cors.rb +31 -34
- data/lib/gcloud/storage/bucket/list.rb +3 -3
- data/lib/gcloud/storage/connection.rb +11 -7
- data/lib/gcloud/storage/credentials.rb +3 -3
- data/lib/gcloud/storage/errors.rb +11 -8
- data/lib/gcloud/storage/file.rb +129 -171
- data/lib/gcloud/storage/file/acl.rb +51 -99
- data/lib/gcloud/storage/file/list.rb +3 -3
- data/lib/gcloud/storage/file/verifier.rb +3 -2
- data/lib/gcloud/storage/project.rb +111 -132
- data/lib/gcloud/upload.rb +4 -7
- data/lib/gcloud/version.rb +2 -4
- data/lib/google/api/annotations.rb +14 -0
- data/lib/google/api/http.rb +30 -0
- data/lib/google/api/label.rb +24 -0
- data/lib/google/api/monitored_resource.rb +25 -0
- data/lib/google/datastore/v1beta3/datastore.rb +115 -0
- data/lib/google/datastore/v1beta3/datastore_services.rb +33 -0
- data/lib/google/datastore/v1beta3/entity.rb +63 -0
- data/lib/google/datastore/v1beta3/query.rb +128 -0
- data/lib/google/devtools/cloudtrace/v1/trace.rb +78 -0
- data/lib/google/devtools/cloudtrace/v1/trace_services.rb +32 -0
- data/lib/google/example/library/v1/library.rb +91 -0
- data/lib/google/example/library/v1/library_services.rb +40 -0
- data/lib/google/iam/v1/iam_policy.rb +33 -0
- data/lib/google/iam/v1/iam_policy_services.rb +30 -0
- data/lib/google/iam/v1/policy.rb +25 -0
- data/lib/google/logging/type/http_request.rb +28 -0
- data/lib/google/logging/type/log_severity.rb +27 -0
- data/lib/google/logging/v2/log_entry.rb +44 -0
- data/lib/google/logging/v2/logging.rb +56 -0
- data/lib/google/logging/v2/logging_config.rb +59 -0
- data/lib/google/logging/v2/logging_config_services.rb +32 -0
- data/lib/google/logging/v2/logging_metrics.rb +51 -0
- data/lib/google/logging/v2/logging_metrics_services.rb +32 -0
- data/lib/google/logging/v2/logging_services.rb +31 -0
- data/lib/google/longrunning/operations.rb +50 -0
- data/lib/google/longrunning/operations_services.rb +29 -0
- data/lib/google/protobuf/any.rb +17 -0
- data/lib/google/protobuf/api.rb +31 -0
- data/lib/google/protobuf/descriptor.rb +0 -0
- data/lib/google/protobuf/duration.rb +17 -0
- data/lib/google/protobuf/empty.rb +15 -0
- data/lib/google/protobuf/field_mask.rb +16 -0
- data/lib/google/protobuf/source_context.rb +16 -0
- data/lib/google/protobuf/struct.rb +35 -0
- data/lib/google/protobuf/timestamp.rb +17 -0
- data/lib/google/protobuf/type.rb +79 -0
- data/lib/google/protobuf/wrappers.rb +48 -0
- data/lib/google/pubsub/v1/pubsub.rb +129 -0
- data/lib/google/pubsub/v1/pubsub_services.rb +56 -0
- data/lib/google/pubsub/v1beta2/pubsub.rb +126 -0
- data/lib/google/pubsub/v1beta2/pubsub_services.rb +56 -0
- data/lib/google/rpc/code.rb +32 -0
- data/lib/google/rpc/error_details.rb +61 -0
- data/lib/google/rpc/status.rb +19 -0
- data/lib/google/type/color.rb +20 -0
- data/lib/google/type/date.rb +18 -0
- data/lib/google/type/dayofweek.rb +23 -0
- data/lib/google/type/latlng.rb +17 -0
- data/lib/google/type/money.rb +18 -0
- data/lib/google/type/timeofday.rb +19 -0
- metadata +101 -4
- data/lib/gcloud/pubsub/connection.rb +0 -295
- data/lib/gcloud/pubsub/errors.rb +0 -93
data/lib/gcloud/datastore/key.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
#--
|
2
1
|
# Copyright 2014 Google Inc. All rights reserved.
|
3
2
|
#
|
4
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -13,29 +12,29 @@
|
|
13
12
|
# See the License for the specific language governing permissions and
|
14
13
|
# limitations under the License.
|
15
14
|
|
15
|
+
|
16
16
|
require "gcloud/datastore/proto"
|
17
17
|
|
18
18
|
module Gcloud
|
19
19
|
module Datastore
|
20
20
|
##
|
21
|
-
#
|
21
|
+
# # Key
|
22
22
|
#
|
23
23
|
# Every Datastore record has an identifying key, which includes the record's
|
24
24
|
# entity kind and a unique identifier. The identifier may be either a key
|
25
25
|
# name string, assigned explicitly by the application, or an integer numeric
|
26
26
|
# ID, assigned automatically by Datastore.
|
27
27
|
#
|
28
|
+
# @example
|
28
29
|
# key = Gcloud::Datastore::Key.new "User", "heidi@example.com"
|
30
|
+
#
|
29
31
|
class Key
|
30
32
|
##
|
31
33
|
# The kind of the Key.
|
32
34
|
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
# +String+
|
36
|
-
#
|
37
|
-
# === Example
|
35
|
+
# @return [String]
|
38
36
|
#
|
37
|
+
# @example
|
39
38
|
# key = Gcloud::Datastore::Key.new "User"
|
40
39
|
# key.kind #=> "User"
|
41
40
|
# key.kind = "Task"
|
@@ -45,12 +44,9 @@ module Gcloud
|
|
45
44
|
##
|
46
45
|
# The dataset_id of the Key.
|
47
46
|
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
# +String+
|
51
|
-
#
|
52
|
-
# === Example
|
47
|
+
# @return [String]
|
53
48
|
#
|
49
|
+
# @example
|
54
50
|
# require "gcloud"
|
55
51
|
#
|
56
52
|
# gcloud = Gcloud.new "my-todo-project",
|
@@ -65,12 +61,9 @@ module Gcloud
|
|
65
61
|
##
|
66
62
|
# The namespace of the Key.
|
67
63
|
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
# +String+ or +nil+
|
71
|
-
#
|
72
|
-
# === Example
|
64
|
+
# @return [String, nil]
|
73
65
|
#
|
66
|
+
# @example
|
74
67
|
# require "gcloud"
|
75
68
|
#
|
76
69
|
# gcloud = Gcloud.new "my-todo-project",
|
@@ -85,19 +78,13 @@ module Gcloud
|
|
85
78
|
##
|
86
79
|
# Create a new Key instance.
|
87
80
|
#
|
88
|
-
#
|
89
|
-
#
|
90
|
-
#
|
91
|
-
# The kind of the Key. This is optional. (+String+)
|
92
|
-
# +id_or_name+::
|
93
|
-
# The id or name of the Key. This is optional. (+Integer+ or +String+)
|
94
|
-
#
|
95
|
-
# === Returns
|
81
|
+
# @param [String] kind The kind of the Key. This is optional.
|
82
|
+
# @param [Integer, String] id_or_name The id or name of the Key. This is
|
83
|
+
# optional.
|
96
84
|
#
|
97
|
-
# Gcloud::Datastore::Dataset::Key
|
98
|
-
#
|
99
|
-
# === Example
|
85
|
+
# @return [Gcloud::Datastore::Dataset::Key]
|
100
86
|
#
|
87
|
+
# @example
|
101
88
|
# key = Gcloud::Datastore::Key.new "User", "heidi@example.com"
|
102
89
|
#
|
103
90
|
def initialize kind = nil, id_or_name = nil
|
@@ -110,15 +97,12 @@ module Gcloud
|
|
110
97
|
end
|
111
98
|
|
112
99
|
##
|
113
|
-
# Set the id of the Key.
|
100
|
+
# @private Set the id of the Key.
|
114
101
|
# If a name is already present it will be removed.
|
115
102
|
#
|
116
|
-
#
|
117
|
-
#
|
118
|
-
# +Integer+ or +nil+
|
119
|
-
#
|
120
|
-
# === Example
|
103
|
+
# @return [Integer, nil]
|
121
104
|
#
|
105
|
+
# @example
|
122
106
|
# key = Gcloud::Datastore::Key.new "User", "heidi@example.com"
|
123
107
|
# key.id #=> nil
|
124
108
|
# key.name #=> "heidi@example.com"
|
@@ -126,7 +110,7 @@ module Gcloud
|
|
126
110
|
# key.id #=> 654321
|
127
111
|
# key.name #=> nil
|
128
112
|
#
|
129
|
-
def id= new_id
|
113
|
+
def id= new_id
|
130
114
|
@name = nil if new_id
|
131
115
|
@id = new_id
|
132
116
|
end
|
@@ -134,27 +118,21 @@ module Gcloud
|
|
134
118
|
##
|
135
119
|
# The id of the Key.
|
136
120
|
#
|
137
|
-
#
|
138
|
-
#
|
139
|
-
# +Integer+ or +nil+
|
140
|
-
#
|
141
|
-
# === Example
|
121
|
+
# @return [Integer, nil]
|
142
122
|
#
|
123
|
+
# @example
|
143
124
|
# key = Gcloud::Datastore::Key.new "User", 123456
|
144
125
|
# key.id #=> 123456
|
145
126
|
#
|
146
127
|
attr_reader :id
|
147
128
|
|
148
129
|
##
|
149
|
-
# Set the name of the Key.
|
130
|
+
# @private Set the name of the Key.
|
150
131
|
# If an id is already present it will be removed.
|
151
132
|
#
|
152
|
-
#
|
153
|
-
#
|
154
|
-
# +String+ or +nil+
|
155
|
-
#
|
156
|
-
# === Example
|
133
|
+
# @return [String, nil]
|
157
134
|
#
|
135
|
+
# @example
|
158
136
|
# key = Gcloud::Datastore::Key.new "User", 123456
|
159
137
|
# key.id #=> 123456
|
160
138
|
# key.name #=> nil
|
@@ -162,7 +140,7 @@ module Gcloud
|
|
162
140
|
# key.id #=> nil
|
163
141
|
# key.name #=> "heidi@example.com"
|
164
142
|
#
|
165
|
-
def name= new_name
|
143
|
+
def name= new_name
|
166
144
|
@id = nil if new_name
|
167
145
|
@name = new_name
|
168
146
|
end
|
@@ -170,30 +148,24 @@ module Gcloud
|
|
170
148
|
##
|
171
149
|
# The name of the Key.
|
172
150
|
#
|
173
|
-
#
|
174
|
-
#
|
175
|
-
# +String+ or +nil+
|
176
|
-
#
|
177
|
-
# === Example
|
151
|
+
# @return [String, nil]
|
178
152
|
#
|
153
|
+
# @example
|
179
154
|
# key = Gcloud::Datastore::Key.new "User", "heidi@example.com"
|
180
155
|
# key.name #=> "heidi@example.com"
|
181
156
|
#
|
182
157
|
attr_reader :name
|
183
158
|
|
184
159
|
##
|
185
|
-
# Set the parent of the Key.
|
160
|
+
# @private Set the parent of the Key.
|
186
161
|
#
|
187
|
-
#
|
188
|
-
#
|
189
|
-
# +Key+ or +nil+
|
190
|
-
#
|
191
|
-
# === Example
|
162
|
+
# @return [Key, nil]
|
192
163
|
#
|
164
|
+
# @example
|
193
165
|
# key = Gcloud::Datastore::Key.new "List", "todos"
|
194
166
|
# key.parent = Gcloud::Datastore::Key.new "User", "heidi@example.com"
|
195
167
|
#
|
196
|
-
def parent= new_parent
|
168
|
+
def parent= new_parent
|
197
169
|
# store key if given an entity
|
198
170
|
new_parent = new_parent.key if new_parent.respond_to? :key
|
199
171
|
@parent = new_parent
|
@@ -202,12 +174,9 @@ module Gcloud
|
|
202
174
|
##
|
203
175
|
# The parent of the Key.
|
204
176
|
#
|
205
|
-
#
|
206
|
-
#
|
207
|
-
# +Key+ or +nil+
|
208
|
-
#
|
209
|
-
# === Example
|
177
|
+
# @return [Key, nil]
|
210
178
|
#
|
179
|
+
# @example
|
211
180
|
# require "gcloud"
|
212
181
|
#
|
213
182
|
# gcloud = Gcloud.new
|
@@ -226,12 +195,9 @@ module Gcloud
|
|
226
195
|
# Each inner array contains two values, the kind and the id or name.
|
227
196
|
# If neither an id or name exist then nil will be returned.
|
228
197
|
#
|
229
|
-
#
|
230
|
-
#
|
231
|
-
# Array of arrays
|
232
|
-
#
|
233
|
-
# === Example
|
198
|
+
# @return [Array<Array<(String, String)>>]
|
234
199
|
#
|
200
|
+
# @example
|
235
201
|
# key = Gcloud::Datastore::Key.new "List", "todos"
|
236
202
|
# key.parent = Gcloud::Datastore::Key.new "User", "heidi@example.com"
|
237
203
|
# key.path #=> [["User", "heidi@example.com"], ["List", "todos"]]
|
@@ -245,7 +211,7 @@ module Gcloud
|
|
245
211
|
# Determine if the key is complete.
|
246
212
|
# A complete key has either an id or a name.
|
247
213
|
#
|
248
|
-
# Inverse of #incomplete?
|
214
|
+
# Inverse of {#incomplete?}
|
249
215
|
def complete?
|
250
216
|
!incomplete?
|
251
217
|
end
|
@@ -254,15 +220,14 @@ module Gcloud
|
|
254
220
|
# Determine if the key is incomplete.
|
255
221
|
# An incomplete key has neither an id nor a name.
|
256
222
|
#
|
257
|
-
# Inverse of #complete?
|
223
|
+
# Inverse of {#complete?}
|
258
224
|
def incomplete?
|
259
225
|
kind.nil? || (id.nil? && (name.nil? || name.empty?))
|
260
226
|
end
|
261
227
|
|
262
228
|
##
|
263
|
-
# Convert the Key to a protocol buffer object.
|
264
|
-
|
265
|
-
def to_proto #:nodoc:
|
229
|
+
# @private Convert the Key to a protocol buffer object.
|
230
|
+
def to_proto
|
266
231
|
Proto::Key.new.tap do |k|
|
267
232
|
k.path_element = path.map do |pe_kind, pe_id_or_name|
|
268
233
|
Proto.new_path_element pe_kind, pe_id_or_name
|
@@ -274,9 +239,8 @@ module Gcloud
|
|
274
239
|
# rubocop:disable all
|
275
240
|
|
276
241
|
##
|
277
|
-
# Create a new Key from a protocol buffer object.
|
278
|
-
|
279
|
-
def self.from_proto proto #:nodoc:
|
242
|
+
# @private Create a new Key from a protocol buffer object.
|
243
|
+
def self.from_proto proto
|
280
244
|
# Disable rules because the complexity here is neccessary.
|
281
245
|
key_proto = proto.dup
|
282
246
|
key = Key.new
|
@@ -1,4 +1,3 @@
|
|
1
|
-
#--
|
2
1
|
# Copyright 2015 Google Inc. All rights reserved.
|
3
2
|
#
|
4
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -13,14 +12,15 @@
|
|
13
12
|
# See the License for the specific language governing permissions and
|
14
13
|
# limitations under the License.
|
15
14
|
|
15
|
+
|
16
16
|
module Gcloud
|
17
17
|
module Datastore
|
18
18
|
##
|
19
|
-
#
|
19
|
+
# # Properties
|
20
20
|
#
|
21
21
|
# Hash-like data structure for Datastore properties.
|
22
22
|
#
|
23
|
-
# See Entity#properties
|
23
|
+
# See {Entity#properties}
|
24
24
|
class Properties
|
25
25
|
def initialize properties = {}
|
26
26
|
@hash = {}
|
@@ -1,4 +1,3 @@
|
|
1
|
-
#--
|
2
1
|
# Copyright 2014 Google Inc. All rights reserved.
|
3
2
|
#
|
4
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -13,6 +12,7 @@
|
|
13
12
|
# See the License for the specific language governing permissions and
|
14
13
|
# limitations under the License.
|
15
14
|
|
15
|
+
|
16
16
|
require "gcloud/proto/datastore_v1.pb"
|
17
17
|
require "gcloud/datastore/errors"
|
18
18
|
|
@@ -21,6 +21,8 @@ module Gcloud
|
|
21
21
|
# rubocop:disable all
|
22
22
|
|
23
23
|
##
|
24
|
+
# @private
|
25
|
+
#
|
24
26
|
# Proto is the namespace that contains all Protocol Buffer objects.
|
25
27
|
#
|
26
28
|
# The methods in this module are for convenience in using the
|
@@ -30,7 +32,7 @@ module Gcloud
|
|
30
32
|
# this module's existance, may change in the future.
|
31
33
|
#
|
32
34
|
# You have been warned.
|
33
|
-
module Proto
|
35
|
+
module Proto
|
34
36
|
def self.from_proto_value proto_value
|
35
37
|
if !proto_value.timestamp_microseconds_value.nil?
|
36
38
|
microseconds = proto_value.timestamp_microseconds_value
|
@@ -111,7 +113,7 @@ module Gcloud
|
|
111
113
|
Time.at(microseconds / 1000000, microseconds % 1000000).utc
|
112
114
|
end
|
113
115
|
|
114
|
-
|
116
|
+
@private
|
115
117
|
PROP_FILTER_OPS = {
|
116
118
|
"<" => PropertyFilter::Operator::LESS_THAN,
|
117
119
|
"lt" => PropertyFilter::Operator::LESS_THAN,
|
@@ -245,7 +247,8 @@ module Gcloud
|
|
245
247
|
end
|
246
248
|
end
|
247
249
|
|
248
|
-
|
250
|
+
# @private
|
251
|
+
class Key
|
249
252
|
def dup
|
250
253
|
proto_request_body = ""
|
251
254
|
self.encode proto_request_body
|
@@ -1,4 +1,3 @@
|
|
1
|
-
#--
|
2
1
|
# Copyright 2014 Google Inc. All rights reserved.
|
3
2
|
#
|
4
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -13,6 +12,7 @@
|
|
13
12
|
# See the License for the specific language governing permissions and
|
14
13
|
# limitations under the License.
|
15
14
|
|
15
|
+
|
16
16
|
require "gcloud/datastore/entity"
|
17
17
|
require "gcloud/datastore/key"
|
18
18
|
require "gcloud/datastore/proto"
|
@@ -20,20 +20,24 @@ require "gcloud/datastore/proto"
|
|
20
20
|
module Gcloud
|
21
21
|
module Datastore
|
22
22
|
##
|
23
|
-
#
|
23
|
+
# # Query
|
24
24
|
#
|
25
25
|
# Represents the search criteria against a Datastore.
|
26
26
|
#
|
27
|
+
# @example
|
27
28
|
# query = Gcloud::Datastore::Query.new
|
28
29
|
# query.kind("Task").
|
29
30
|
# where("completed", "=", true)
|
30
31
|
#
|
31
32
|
# entities = dataset.run query
|
33
|
+
#
|
32
34
|
class Query
|
33
35
|
##
|
34
36
|
# Returns a new query object.
|
35
37
|
#
|
38
|
+
# @example
|
36
39
|
# query = Gcloud::Datastore::Query.new
|
40
|
+
#
|
37
41
|
def initialize
|
38
42
|
@_query = Proto::Query.new
|
39
43
|
end
|
@@ -41,10 +45,12 @@ module Gcloud
|
|
41
45
|
##
|
42
46
|
# Add the kind of entities to query.
|
43
47
|
#
|
48
|
+
# @example
|
44
49
|
# query = Gcloud::Datastore::Query.new
|
45
50
|
# query.kind "Task"
|
46
51
|
#
|
47
52
|
# all_tasks = dataset.run query
|
53
|
+
#
|
48
54
|
def kind *kinds
|
49
55
|
@_query.kind ||= Proto::KindExpression.new
|
50
56
|
@_query.kind.name ||= []
|
@@ -55,11 +61,13 @@ module Gcloud
|
|
55
61
|
##
|
56
62
|
# Add a property filter to the query.
|
57
63
|
#
|
64
|
+
# @example
|
58
65
|
# query = Gcloud::Datastore::Query.new
|
59
66
|
# query.kind("Task").
|
60
67
|
# where("completed", "=", true)
|
61
68
|
#
|
62
69
|
# completed_tasks = dataset.run query
|
70
|
+
#
|
63
71
|
def where name, operator, value
|
64
72
|
# Initialize filter
|
65
73
|
@_query.filter ||= Proto.new_filter.tap do |f|
|
@@ -78,11 +86,13 @@ module Gcloud
|
|
78
86
|
##
|
79
87
|
# Add a filter for entities that inherit from a key.
|
80
88
|
#
|
89
|
+
# @example
|
81
90
|
# query = Gcloud::Datastore::Query.new
|
82
91
|
# query.kind("Task").
|
83
92
|
# ancestor(parent.key)
|
84
93
|
#
|
85
94
|
# completed_tasks = dataset.run query
|
95
|
+
#
|
86
96
|
def ancestor parent
|
87
97
|
# Use key if given an entity
|
88
98
|
parent = parent.key if parent.respond_to? :key
|
@@ -95,11 +105,13 @@ module Gcloud
|
|
95
105
|
# To sort in descending order, provide a second argument
|
96
106
|
# of a string or symbol that starts with "d".
|
97
107
|
#
|
108
|
+
# @example
|
98
109
|
# query = Gcloud::Datastore::Query.new
|
99
110
|
# query.kind("Task").
|
100
111
|
# order("due", :desc)
|
101
112
|
#
|
102
113
|
# sorted_tasks = dataset.run query
|
114
|
+
#
|
103
115
|
def order name, direction = :asc
|
104
116
|
@_query.order ||= []
|
105
117
|
po = Proto::PropertyOrder.new
|
@@ -113,11 +125,13 @@ module Gcloud
|
|
113
125
|
##
|
114
126
|
# Set a limit on the number of results to be returned.
|
115
127
|
#
|
128
|
+
# @example
|
116
129
|
# query = Gcloud::Datastore::Query.new
|
117
130
|
# query.kind("Task").
|
118
131
|
# limit(10)
|
119
132
|
#
|
120
133
|
# paginated_tasks = dataset.run query
|
134
|
+
#
|
121
135
|
def limit num
|
122
136
|
@_query.limit = num
|
123
137
|
self
|
@@ -126,12 +140,14 @@ module Gcloud
|
|
126
140
|
##
|
127
141
|
# Set an offset for the results to be returned.
|
128
142
|
#
|
143
|
+
# @example
|
129
144
|
# query = Gcloud::Datastore::Query.new
|
130
145
|
# query.kind("Task").
|
131
146
|
# limit(10).
|
132
147
|
# offset(20)
|
133
148
|
#
|
134
149
|
# paginated_tasks = dataset.run query
|
150
|
+
#
|
135
151
|
def offset num
|
136
152
|
@_query.offset = num
|
137
153
|
self
|
@@ -140,12 +156,14 @@ module Gcloud
|
|
140
156
|
##
|
141
157
|
# Set the cursor to start the results at.
|
142
158
|
#
|
159
|
+
# @example
|
143
160
|
# query = Gcloud::Datastore::Query.new
|
144
161
|
# query.kind("Task").
|
145
162
|
# limit(10).
|
146
163
|
# cursor(task_cursor)
|
147
164
|
#
|
148
165
|
# paginated_tasks = dataset.run query
|
166
|
+
#
|
149
167
|
def start cursor
|
150
168
|
@_query.start_cursor = Proto.decode_cursor cursor
|
151
169
|
self
|
@@ -155,11 +173,13 @@ module Gcloud
|
|
155
173
|
##
|
156
174
|
# Retrieve only select properties from the matched entities.
|
157
175
|
#
|
176
|
+
# @example
|
158
177
|
# query = Gcloud::Datastore::Query.new
|
159
178
|
# query.kind("Task").
|
160
179
|
# select("completed", "due")
|
161
180
|
#
|
162
181
|
# partial_tasks = dataset.run query
|
182
|
+
#
|
163
183
|
def select *names
|
164
184
|
@_query.projection ||= []
|
165
185
|
@_query.projection += Proto.new_property_expressions(*names)
|
@@ -170,18 +190,21 @@ module Gcloud
|
|
170
190
|
##
|
171
191
|
# Group results by a list of properties.
|
172
192
|
#
|
193
|
+
# @example
|
173
194
|
# query = Gcloud::Datastore::Query.new
|
174
195
|
# query.kind("Task").
|
175
196
|
# group_by("completed")
|
176
197
|
#
|
177
198
|
# grouped_tasks = dataset.run query
|
199
|
+
#
|
178
200
|
def group_by *names
|
179
201
|
@_query.group_by ||= []
|
180
202
|
@_query.group_by += Proto.new_property_references(*names)
|
181
203
|
self
|
182
204
|
end
|
183
205
|
|
184
|
-
|
206
|
+
# @private
|
207
|
+
def to_proto
|
185
208
|
@_query
|
186
209
|
end
|
187
210
|
end
|