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/credentials.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,19 +12,19 @@
|
|
13
12
|
# See the License for the specific language governing permissions and
|
14
13
|
# limitations under the License.
|
15
14
|
|
15
|
+
|
16
16
|
require "json"
|
17
17
|
require "signet/oauth_2/client"
|
18
18
|
require "forwardable"
|
19
19
|
require "googleauth"
|
20
20
|
|
21
|
-
#--
|
22
|
-
# Google Cloud Credentials
|
23
21
|
module Gcloud
|
24
22
|
##
|
23
|
+
# @private
|
25
24
|
# Represents the OAuth 2.0 signing logic.
|
26
25
|
# This class is intended to be inherited by API-specific classes
|
27
26
|
# which overrides the SCOPE constant.
|
28
|
-
class Credentials
|
27
|
+
class Credentials
|
29
28
|
TOKEN_CREDENTIAL_URI = "https://accounts.google.com/o/oauth2/token"
|
30
29
|
AUDIENCE = "https://accounts.google.com/o/oauth2/token"
|
31
30
|
SCOPE = []
|
@@ -59,9 +58,6 @@ module Gcloud
|
|
59
58
|
@client.fetch_access_token!
|
60
59
|
end
|
61
60
|
|
62
|
-
# rubocop:disable all
|
63
|
-
# Disabled rubocop because this is intentionally complex.
|
64
|
-
|
65
61
|
##
|
66
62
|
# Returns the default credentials.
|
67
63
|
#
|
@@ -88,8 +84,6 @@ module Gcloud
|
|
88
84
|
new client
|
89
85
|
end
|
90
86
|
|
91
|
-
# rubocop:enable all
|
92
|
-
|
93
87
|
protected
|
94
88
|
|
95
89
|
##
|
data/lib/gcloud/datastore.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,43 +12,38 @@
|
|
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"
|
17
17
|
require "gcloud/datastore/errors"
|
18
18
|
require "gcloud/datastore/dataset"
|
19
19
|
require "gcloud/datastore/transaction"
|
20
20
|
require "gcloud/datastore/credentials"
|
21
21
|
|
22
|
-
#--
|
23
|
-
# Google Cloud Datastore
|
24
22
|
module Gcloud
|
25
23
|
##
|
26
24
|
# Creates a new object for connecting to the Datastore service.
|
27
25
|
# Each call creates a new connection.
|
28
26
|
#
|
29
|
-
#
|
27
|
+
# For more information on connecting to Google Cloud see the [Authentication
|
28
|
+
# Guide](https://googlecloudplatform.github.io/gcloud-ruby/#/docs/guides/authentication).
|
30
29
|
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
# APIs}[https://developers.google.com/identity/protocols/OAuth2]. (+String+
|
40
|
-
# or +Array+)
|
30
|
+
# @param [String] project Dataset identifier for the Datastore you are
|
31
|
+
# connecting to.
|
32
|
+
# @param [String, Hash] keyfile Keyfile downloaded from Google Cloud. If file
|
33
|
+
# path the file must be readable.
|
34
|
+
# @param [String, Array<String>] scope The OAuth 2.0 scopes controlling the
|
35
|
+
# set of resources and operations that the connection can access. See [Using
|
36
|
+
# OAuth 2.0 to Access Google
|
37
|
+
# APIs](https://developers.google.com/identity/protocols/OAuth2).
|
41
38
|
#
|
42
39
|
# The default scopes are:
|
43
40
|
#
|
44
|
-
# *
|
45
|
-
# *
|
46
|
-
#
|
47
|
-
# === Returns
|
41
|
+
# * `https://www.googleapis.com/auth/datastore`
|
42
|
+
# * `https://www.googleapis.com/auth/userinfo.email`
|
48
43
|
#
|
49
|
-
# Gcloud::Datastore::Dataset
|
50
|
-
#
|
51
|
-
# === Example
|
44
|
+
# @return [Gcloud::Datastore::Dataset]
|
52
45
|
#
|
46
|
+
# @example
|
53
47
|
# require "gcloud/datastore"
|
54
48
|
#
|
55
49
|
# dataset = Gcloud.datastore "my-todo-project",
|
@@ -73,7 +67,7 @@ module Gcloud
|
|
73
67
|
end
|
74
68
|
|
75
69
|
##
|
76
|
-
#
|
70
|
+
# # Google Cloud Datastore
|
77
71
|
#
|
78
72
|
# Google Cloud Datastore is a fully managed, schemaless database for storing
|
79
73
|
# non-relational data. You should feel at home if you are familiar with
|
@@ -81,235 +75,265 @@ module Gcloud
|
|
81
75
|
# make the most of using Datastore.
|
82
76
|
#
|
83
77
|
# Gcloud's goal is to provide a API that is familiar and comfortable to
|
84
|
-
# Rubyists. Authentication is handled by Gcloud#datastore. You can provide
|
78
|
+
# Rubyists. Authentication is handled by {Gcloud#datastore}. You can provide
|
85
79
|
# the project and credential information to connect to the Datastore service,
|
86
80
|
# or if you are running on Google Compute Engine this configuration is taken
|
87
81
|
# care of for you.
|
88
82
|
#
|
89
|
-
#
|
83
|
+
# ```ruby
|
84
|
+
# require "gcloud"
|
90
85
|
#
|
91
|
-
#
|
92
|
-
#
|
93
|
-
#
|
94
|
-
#
|
95
|
-
#
|
96
|
-
#
|
86
|
+
# gcloud = Gcloud.new "my-todo-project",
|
87
|
+
# "/path/to/keyfile.json"
|
88
|
+
# dataset = gcloud.datastore
|
89
|
+
# entity = dataset.find "Task", "start"
|
90
|
+
# entity["completed"] = true
|
91
|
+
# dataset.save entity
|
92
|
+
# ```
|
97
93
|
#
|
98
94
|
# You can learn more about various options for connection on the
|
99
|
-
#
|
95
|
+
# [Authentication
|
96
|
+
# Guide](https://googlecloudplatform.github.io/gcloud-ruby/#/docs/guides/authentication).
|
100
97
|
#
|
101
98
|
# To learn more about Datastore, read the
|
102
|
-
#
|
103
|
-
#
|
99
|
+
# [Google Cloud Datastore Concepts Overview
|
100
|
+
# ](https://cloud.google.com/datastore/docs/concepts/overview).
|
104
101
|
#
|
105
|
-
#
|
102
|
+
# ## Retrieving Records
|
106
103
|
#
|
107
104
|
# Records, called "entities" in Datastore, are retrieved by using a Key.
|
108
105
|
# The Key is more than a numeric identifier, it is a complex data structure
|
109
106
|
# that can be used to model relationships. The simplest Key has a string
|
110
107
|
# <tt>kind</tt> value, and either a numeric <tt>id</tt> value, or a string
|
111
108
|
# <tt>name</tt> value. A single record can be retrieved by calling
|
112
|
-
# Gcloud::Datastore::Dataset#find and passing the parts of the key:
|
109
|
+
# {Gcloud::Datastore::Dataset#find} and passing the parts of the key:
|
113
110
|
#
|
114
|
-
#
|
111
|
+
# ```ruby
|
112
|
+
# require "gcloud"
|
115
113
|
#
|
116
|
-
#
|
117
|
-
#
|
118
|
-
#
|
114
|
+
# gcloud = Gcloud.new
|
115
|
+
# dataset = gcloud.datastore
|
116
|
+
# entity = dataset.find "Task", "start"
|
117
|
+
# ```
|
119
118
|
#
|
120
|
-
# Optionally, Gcloud::Datastore::Dataset#find can be given a Key object:
|
119
|
+
# Optionally, {Gcloud::Datastore::Dataset#find} can be given a Key object:
|
121
120
|
#
|
122
|
-
#
|
121
|
+
# ```ruby
|
122
|
+
# require "gcloud"
|
123
123
|
#
|
124
|
-
#
|
125
|
-
#
|
126
|
-
#
|
127
|
-
#
|
124
|
+
# gcloud = Gcloud.new
|
125
|
+
# dataset = gcloud.datastore
|
126
|
+
# key = dataset.key "Task", 12345
|
127
|
+
# entity = dataset.find key
|
128
|
+
# ```
|
128
129
|
#
|
129
|
-
# See Gcloud::Datastore::Dataset#find
|
130
|
+
# See {Gcloud::Datastore::Dataset#find}
|
130
131
|
#
|
131
|
-
#
|
132
|
+
# ## Querying Records
|
132
133
|
#
|
133
134
|
# Multiple records can be found that match criteria.
|
134
|
-
# (See Gcloud::Datastore::Query#where)
|
135
|
+
# (See {Gcloud::Datastore::Query#where})
|
135
136
|
#
|
136
|
-
#
|
137
|
+
# ```ruby
|
138
|
+
# require "gcloud"
|
137
139
|
#
|
138
|
-
#
|
139
|
-
#
|
140
|
-
#
|
141
|
-
#
|
142
|
-
#
|
140
|
+
# gcloud = Gcloud.new
|
141
|
+
# dataset = gcloud.datastore
|
142
|
+
# query = dataset.query("List").
|
143
|
+
# where("active", "=", true)
|
144
|
+
# active_lists = dataset.run query
|
145
|
+
# ```
|
143
146
|
#
|
144
|
-
# Records can also be ordered. (See Gcloud::Datastore::Query#order)
|
147
|
+
# Records can also be ordered. (See {Gcloud::Datastore::Query#order})
|
145
148
|
#
|
146
|
-
#
|
149
|
+
# ```ruby
|
150
|
+
# require "gcloud"
|
147
151
|
#
|
148
|
-
#
|
149
|
-
#
|
150
|
-
#
|
151
|
-
#
|
152
|
-
#
|
153
|
-
#
|
152
|
+
# gcloud = Gcloud.new
|
153
|
+
# dataset = gcloud.datastore
|
154
|
+
# query = dataset.query("List").
|
155
|
+
# where("active", "=", true).
|
156
|
+
# order("name")
|
157
|
+
# active_lists = dataset.run query
|
158
|
+
# ```
|
154
159
|
#
|
155
160
|
# The number of records returned can be specified.
|
156
|
-
# (See Gcloud::Datastore::Query#limit)
|
161
|
+
# (See {Gcloud::Datastore::Query#limit})
|
157
162
|
#
|
158
|
-
#
|
163
|
+
# ```ruby
|
164
|
+
# require "gcloud"
|
159
165
|
#
|
160
|
-
#
|
161
|
-
#
|
162
|
-
#
|
163
|
-
#
|
164
|
-
#
|
165
|
-
#
|
166
|
-
#
|
166
|
+
# gcloud = Gcloud.new
|
167
|
+
# dataset = gcloud.datastore
|
168
|
+
# query = dataset.query("List").
|
169
|
+
# where("active", "=", true).
|
170
|
+
# order("name").
|
171
|
+
# limit(5)
|
172
|
+
# active_lists = dataset.run query
|
173
|
+
# ```
|
167
174
|
#
|
168
175
|
# Records' Key structures can also be queried.
|
169
|
-
# (See Gcloud::Datastore::Query#ancestor)
|
176
|
+
# (See {Gcloud::Datastore::Query#ancestor})
|
170
177
|
#
|
171
|
-
#
|
178
|
+
# ```ruby
|
179
|
+
# require "gcloud"
|
172
180
|
#
|
173
|
-
#
|
174
|
-
#
|
181
|
+
# gcloud = Gcloud.new
|
182
|
+
# dataset = gcloud.datastore
|
175
183
|
#
|
176
|
-
#
|
177
|
-
#
|
178
|
-
#
|
179
|
-
#
|
184
|
+
# list = dataset.find "List", "todos"
|
185
|
+
# query = dataset.query("Task").
|
186
|
+
# ancestor(list.key)
|
187
|
+
# items = dataset.run query
|
188
|
+
# ```
|
180
189
|
#
|
181
|
-
# See Gcloud::Datastore::Query and Gcloud::Datastore::Dataset#run
|
190
|
+
# See {Gcloud::Datastore::Query} and {Gcloud::Datastore::Dataset#run}
|
182
191
|
#
|
183
|
-
#
|
192
|
+
# ## Paginating Records
|
184
193
|
#
|
185
194
|
# All Records may not return at once, requiring multiple calls to Datastore
|
186
195
|
# to return them all. The returned records will have a <tt>cursor</tt> if
|
187
196
|
# there are more available.
|
188
197
|
#
|
189
|
-
#
|
198
|
+
# ```ruby
|
199
|
+
# require "gcloud"
|
190
200
|
#
|
191
|
-
#
|
192
|
-
#
|
201
|
+
# gcloud = Gcloud.new
|
202
|
+
# dataset = gcloud.datastore
|
193
203
|
#
|
194
|
-
#
|
195
|
-
#
|
196
|
-
#
|
197
|
-
#
|
198
|
-
#
|
199
|
-
#
|
200
|
-
#
|
201
|
-
#
|
202
|
-
# end
|
203
|
-
# # break loop if no more tasks available
|
204
|
-
# break if tmp_tasks.cursor.nil?
|
205
|
-
# # set cursor on the query
|
206
|
-
# query = query.cursor tmp_tasks.cursor
|
207
|
-
# # query for more records
|
208
|
-
# tmp_tasks = dataset.run query
|
204
|
+
# list = dataset.find "List", "todos"
|
205
|
+
# query = dataset.query("Task").
|
206
|
+
# ancestor(list.key)
|
207
|
+
# all_tasks = []
|
208
|
+
# tmp_tasks = dataset.run query
|
209
|
+
# while tmp_tasks.any? do
|
210
|
+
# tmp_tasks.each do |task|
|
211
|
+
# all_tasks << task
|
209
212
|
# end
|
213
|
+
# # break loop if no more tasks available
|
214
|
+
# break if tmp_tasks.cursor.nil?
|
215
|
+
# # set cursor on the query
|
216
|
+
# query = query.cursor tmp_tasks.cursor
|
217
|
+
# # query for more records
|
218
|
+
# tmp_tasks = dataset.run query
|
219
|
+
# end
|
220
|
+
# ```
|
210
221
|
#
|
211
|
-
# See Gcloud::Datastore::Dataset::LookupResults and
|
212
|
-
# Gcloud::Datastore::Dataset::QueryResults
|
222
|
+
# See {Gcloud::Datastore::Dataset::LookupResults} and
|
223
|
+
# {Gcloud::Datastore::Dataset::QueryResults}
|
213
224
|
#
|
214
|
-
#
|
225
|
+
# ## Creating Records
|
215
226
|
#
|
216
|
-
# New entities can be created and persisted buy calling
|
217
|
-
# The entity must have a Key to be saved.
|
218
|
-
# it will be completed when saved.
|
227
|
+
# New entities can be created and persisted buy calling
|
228
|
+
# {Gcloud::Datastore::Dataset#save}. The entity must have a Key to be saved.
|
229
|
+
# If the Key is incomplete then it will be completed when saved.
|
219
230
|
#
|
220
|
-
#
|
231
|
+
# ```ruby
|
232
|
+
# require "gcloud"
|
221
233
|
#
|
222
|
-
#
|
223
|
-
#
|
224
|
-
#
|
225
|
-
#
|
226
|
-
#
|
227
|
-
#
|
228
|
-
#
|
229
|
-
#
|
234
|
+
# gcloud = Gcloud.new
|
235
|
+
# dataset = gcloud.datastore
|
236
|
+
# entity = dataset.entity "User" do |e|
|
237
|
+
# e["name"] = "Heidi Henderson"
|
238
|
+
# end
|
239
|
+
# entity.key.id #=> nil
|
240
|
+
# dataset.save entity
|
241
|
+
# entity.key.id #=> 123456789
|
242
|
+
# ```
|
230
243
|
#
|
231
|
-
#
|
244
|
+
# ## Updating Records
|
232
245
|
#
|
233
246
|
# Entities hold properties. A property has a name that is a string or symbol,
|
234
247
|
# and a value that is an object. Most value objects are supported, including
|
235
248
|
# String, Integer, Date, Time, and even other Entity or Key objects. Changes
|
236
|
-
# to the Entity's properties are persisted by calling
|
237
|
-
#
|
238
|
-
#
|
239
|
-
#
|
240
|
-
#
|
241
|
-
#
|
242
|
-
#
|
243
|
-
#
|
244
|
-
#
|
245
|
-
#
|
246
|
-
#
|
247
|
-
#
|
248
|
-
#
|
249
|
+
# to the Entity's properties are persisted by calling
|
250
|
+
# {Gcloud::Datastore::Dataset#save}.
|
251
|
+
#
|
252
|
+
# ```ruby
|
253
|
+
# require "gcloud"
|
254
|
+
#
|
255
|
+
# gcloud = Gcloud.new
|
256
|
+
# dataset = gcloud.datastore
|
257
|
+
# entity = dataset.find "User", "heidi"
|
258
|
+
# # Read the status property
|
259
|
+
# entity["status"] #=> "inactive"
|
260
|
+
# # Write the status property
|
261
|
+
# entity["status"] = "active"
|
262
|
+
# # Persist the changes
|
263
|
+
# dataset.save entity
|
264
|
+
# ```
|
249
265
|
#
|
250
|
-
#
|
266
|
+
# ## Deleting Records
|
251
267
|
#
|
252
|
-
# Entities can be removed from Datastore by calling
|
253
|
-
# the Entity object or the
|
268
|
+
# Entities can be removed from Datastore by calling
|
269
|
+
# {Gcloud::Datastore::Dataset#delete} and passing the Entity object or the
|
270
|
+
# entity's Key object.
|
254
271
|
#
|
255
|
-
#
|
272
|
+
# ```ruby
|
273
|
+
# require "gcloud"
|
256
274
|
#
|
257
|
-
#
|
258
|
-
#
|
259
|
-
#
|
260
|
-
#
|
275
|
+
# gcloud = Gcloud.new
|
276
|
+
# dataset = gcloud.datastore
|
277
|
+
# entity = dataset.find "User", "heidi"
|
278
|
+
# dataset.delete entity
|
279
|
+
# ```
|
261
280
|
#
|
262
|
-
#
|
281
|
+
# ## Transactions
|
263
282
|
#
|
264
283
|
# Complex logic can be wrapped in a Transaction. All queries and updates
|
265
|
-
# within the Dataset#transaction block are run within the
|
266
|
-
# and will be automatically committed when the block
|
284
|
+
# within the {Gcloud::Datastore::Dataset#transaction} block are run within the
|
285
|
+
# transaction scope, and will be automatically committed when the block
|
286
|
+
# completes.
|
267
287
|
#
|
268
|
-
#
|
288
|
+
# ```ruby
|
289
|
+
# require "gcloud"
|
269
290
|
#
|
270
|
-
#
|
271
|
-
#
|
291
|
+
# gcloud = Gcloud.new
|
292
|
+
# dataset = gcloud.datastore
|
272
293
|
#
|
273
|
-
#
|
294
|
+
# key = dataset.key "User", "heidi"
|
274
295
|
#
|
275
|
-
#
|
276
|
-
#
|
277
|
-
#
|
278
|
-
#
|
296
|
+
# user = dataset.entity key do |u|
|
297
|
+
# u["name"] = "Heidi Henderson"
|
298
|
+
# u["email"] = "heidi@example.net"
|
299
|
+
# end
|
279
300
|
#
|
280
|
-
#
|
281
|
-
#
|
282
|
-
#
|
283
|
-
# end
|
301
|
+
# dataset.transaction do |tx|
|
302
|
+
# if tx.find(user.key).nil?
|
303
|
+
# tx.save user
|
284
304
|
# end
|
305
|
+
# end
|
306
|
+
# ```
|
285
307
|
#
|
286
308
|
# Alternatively, if no block is given the transaction object is returned
|
287
309
|
# allowing you to commit or rollback manually.
|
288
310
|
#
|
289
|
-
#
|
311
|
+
# ```ruby
|
312
|
+
# require "gcloud"
|
290
313
|
#
|
291
|
-
#
|
292
|
-
#
|
314
|
+
# gcloud = Gcloud.new
|
315
|
+
# dataset = gcloud.datastore
|
293
316
|
#
|
294
|
-
#
|
317
|
+
# key = dataset.key "User", "heidi"
|
295
318
|
#
|
296
|
-
#
|
297
|
-
#
|
298
|
-
#
|
299
|
-
#
|
319
|
+
# user = dataset.entity key do |u|
|
320
|
+
# u["name"] = "Heidi Henderson"
|
321
|
+
# u["email"] = "heidi@example.net"
|
322
|
+
# end
|
300
323
|
#
|
301
|
-
#
|
302
|
-
#
|
303
|
-
#
|
304
|
-
#
|
305
|
-
# end
|
306
|
-
# tx.commit
|
307
|
-
# rescue
|
308
|
-
# tx.rollback
|
324
|
+
# tx = dataset.transaction
|
325
|
+
# begin
|
326
|
+
# if tx.find(user.key).nil?
|
327
|
+
# tx.save user
|
309
328
|
# end
|
310
|
-
#
|
311
|
-
#
|
312
|
-
#
|
329
|
+
# tx.commit
|
330
|
+
# rescue
|
331
|
+
# tx.rollback
|
332
|
+
# end
|
333
|
+
# ```
|
334
|
+
#
|
335
|
+
# See {Gcloud::Datastore::Transaction} and
|
336
|
+
# {Gcloud::Datastore::Dataset#transaction}
|
313
337
|
module Datastore
|
314
338
|
end
|
315
339
|
end
|