google-cloud-datastore 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee669c1788eabbeab4c54a4e3c70ef523eaf29ea39d67fff4b8907c128c06a86
4
- data.tar.gz: e3ed585c57076f65a53901f1a02027ddeda91e54ec7a0526e85c1e74f15c63aa
3
+ metadata.gz: d5158282d2e12b211e22031224f6f4e18e48e621f824cf21411cf7d4283f3150
4
+ data.tar.gz: 88de52c6fab28a2e66ad66dc96867c19b08a665da4eb61d478538472ea83ff27
5
5
  SHA512:
6
- metadata.gz: 4cb9965dda5f5255a7cafa68516a3a9dbbdd03c0ea00ce2a64d22acfcbfd2bca476adf03871c56508ace442d7fb0c58013ad35b2f3d02895f071cdc5fe9be030
7
- data.tar.gz: ce4faf4d6a03e3cd9f952689a78b7a440076ec82fdbb1d1cb09278f8c2039fb5b56bbf92e9785e08599abaf1790c994700d52555808a9579c44447bd797c7276
6
+ metadata.gz: 38d06cae20a6f5ed9125af1aa2a2314d18290608fe0dbf810c3cdea855ca615fb1de64ccb05e04c16a5fc63acd3786fc4fc24c25d8cba5238c38137785662fda
7
+ data.tar.gz: 411b854b3f2f1f05d274da447b3779b79b19ba2831db349d52bf139bbdda1cc72750c530764ba586da9ae0ebe4b51ae0a040853494d3b327942a6e719a11e0dc
@@ -20,6 +20,8 @@
20
20
 
21
21
  gem "google-cloud-core"
22
22
  require "google/cloud"
23
+ require "google/cloud/config"
24
+ require "googleauth"
23
25
 
24
26
  module Google
25
27
  module Cloud
@@ -123,3 +125,31 @@ module Google
123
125
  end
124
126
  end
125
127
  end
128
+
129
+ # Set the default bigquery configuration
130
+ Google::Cloud.configure.add_config! :datastore do |config|
131
+ default_project = Google::Cloud::Config.deferred do
132
+ ENV["DATASTORE_DATASET"] || ENV["DATASTORE_PROJECT"]
133
+ end
134
+ default_creds = Google::Cloud::Config.deferred do
135
+ Google::Cloud::Config.credentials_from_env(
136
+ "DATASTORE_CREDENTIALS", "DATASTORE_CREDENTIALS_JSON",
137
+ "DATASTORE_KEYFILE", "DATASTORE_KEYFILE_JSON"
138
+ )
139
+ end
140
+ default_emulator = Google::Cloud::Config.deferred do
141
+ ENV["DATASTORE_EMULATOR_HOST"]
142
+ end
143
+
144
+ config.add_field! :project_id, default_project, match: String, allow_nil: true
145
+ config.add_alias! :project, :project_id
146
+ config.add_field! :credentials, default_creds,
147
+ match: [String, Hash, Google::Auth::Credentials],
148
+ allow_nil: true
149
+ config.add_alias! :keyfile, :credentials
150
+ config.add_field! :scope, nil, match: [String, Array]
151
+ config.add_field! :timeout, nil, match: Integer
152
+ config.add_field! :client_config, nil, match: Hash
153
+ config.add_field! :emulator_host, default_emulator,
154
+ match: String, allow_nil: true
155
+ end
@@ -18,6 +18,8 @@ require "google/cloud/datastore/errors"
18
18
  require "google/cloud/datastore/dataset"
19
19
  require "google/cloud/datastore/transaction"
20
20
  require "google/cloud/datastore/credentials"
21
+ require "google/cloud/config"
22
+ require "google/cloud/env"
21
23
 
22
24
  module Google
23
25
  module Cloud
@@ -29,11 +31,14 @@ module Google
29
31
  # relational databases, but there are some key differences to be aware of to
30
32
  # make the most of using Datastore.
31
33
  #
32
- # The goal of google-cloud is to provide a API that is comfortable to
33
- # Rubyists. Authentication is handled by {Google::Cloud#datastore}. You can
34
- # provide the project and credential information to connect to the Datastore
35
- # service, or if you are running on Google Compute Engine this configuration
36
- # is taken care of for you.
34
+ # The goal of google-cloud is to provide an API that is comfortable to
35
+ # Rubyists. Your authentication credentials are detected automatically in
36
+ # Google Cloud Platform environments such as Google Compute Engine, Google
37
+ # App Engine and Google Kubernetes Engine. In other environments you can
38
+ # configure authentication easily, either directly in your code or via
39
+ # environment variables. Read more about the options for connecting in the
40
+ # [Authentication
41
+ # Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/authentication).
37
42
  #
38
43
  # ```ruby
39
44
  # require "google/cloud/datastore"
@@ -586,7 +591,7 @@ module Google
586
591
  # @param [Hash] client_config A hash of values to override the default
587
592
  # behavior of the API client. See Google::Gax::CallSettings. Optional.
588
593
  # @param [String] emulator_host Datastore emulator host. Optional.
589
- # If the param is nil, ENV["DATASTORE_EMULATOR_HOST"] will be used.
594
+ # If the param is nil, uses the value of the `emulator_host` config.
590
595
  # @param [String] project Alias for the `project_id` argument. Deprecated.
591
596
  # @param [String] keyfile Alias for the `credentials` argument.
592
597
  # Deprecated.
@@ -613,20 +618,24 @@ module Google
613
618
  def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil,
614
619
  client_config: nil, emulator_host: nil, project: nil,
615
620
  keyfile: nil
616
- project_id ||= (project || Datastore::Dataset.default_project_id)
621
+ project_id ||= (project || default_project_id)
617
622
  project_id = project_id.to_s # Always cast to a string
618
- fail ArgumentError, "project_id is missing" if project_id.empty?
623
+ raise ArgumentError, "project_id is missing" if project_id.empty?
619
624
 
620
- emulator_host ||= ENV["DATASTORE_EMULATOR_HOST"]
625
+ scope ||= configure.scope
626
+ timeout ||= configure.timeout
627
+ client_config ||= configure.client_config
628
+ emulator_host ||= configure.emulator_host
621
629
  if emulator_host
622
630
  return Datastore::Dataset.new(
623
631
  Datastore::Service.new(
624
632
  project_id, :this_channel_is_insecure,
625
- host: emulator_host, client_config: client_config))
633
+ host: emulator_host, client_config: client_config
634
+ )
635
+ )
626
636
  end
627
637
 
628
- credentials ||= keyfile
629
- credentials ||= Datastore::Credentials.default(scope: scope)
638
+ credentials ||= (keyfile || default_credentials(scope: scope))
630
639
  unless credentials.is_a? Google::Auth::Credentials
631
640
  credentials = Datastore::Credentials.new credentials, scope: scope
632
641
  end
@@ -634,7 +643,53 @@ module Google
634
643
  Datastore::Dataset.new(
635
644
  Datastore::Service.new(
636
645
  project_id, credentials,
637
- timeout: timeout, client_config: client_config))
646
+ timeout: timeout, client_config: client_config
647
+ )
648
+ )
649
+ end
650
+
651
+ ##
652
+ # Configure the Google Cloud Datastore library.
653
+ #
654
+ # The following Datastore configuration parameters are supported:
655
+ #
656
+ # * `project_id` - (String) Identifier for a Datastore project. (The
657
+ # parameter `project` is considered deprecated, but may also be used.)
658
+ # * `credentials` - (String, Hash, Google::Auth::Credentials) The path to
659
+ # the keyfile as a String, the contents of the keyfile as a Hash, or a
660
+ # Google::Auth::Credentials object. (See {Datastore::Credentials}) (The
661
+ # parameter `keyfile` is considered deprecated, but may also be used.)
662
+ # * `scope` - (String, Array<String>) The OAuth 2.0 scopes controlling
663
+ # the set of resources and operations that the connection can access.
664
+ # * `timeout` - (Integer) Default timeout to use in requests.
665
+ # * `client_config` - (Hash) A hash of values to override the default
666
+ # behavior of the API client.
667
+ # * `emulator_host` - (String) Host name of the emulator. Defaults to
668
+ # `ENV["DATASTORE_EMULATOR_HOST"]`
669
+ #
670
+ # @return [Google::Cloud::Config] The configuration object the
671
+ # Google::Cloud::Datastore library uses.
672
+ #
673
+ def self.configure
674
+ yield Google::Cloud.configure.datastore if block_given?
675
+
676
+ Google::Cloud.configure.datastore
677
+ end
678
+
679
+ ##
680
+ # @private Default project.
681
+ def self.default_project_id
682
+ Google::Cloud.configure.datastore.project_id ||
683
+ Google::Cloud.configure.project_id ||
684
+ Google::Cloud.env.project_id
685
+ end
686
+
687
+ ##
688
+ # @private Default credentials.
689
+ def self.default_credentials scope: nil
690
+ Google::Cloud.configure.datastore.credentials ||
691
+ Google::Cloud.configure.credentials ||
692
+ Datastore::Credentials.default(scope: scope)
638
693
  end
639
694
  end
640
695
  end
@@ -64,7 +64,7 @@ module Google
64
64
  # Do not save yet
65
65
  entities
66
66
  end
67
- alias_method :upsert, :save
67
+ alias upsert save
68
68
 
69
69
  ##
70
70
  # Inserts entities to the Datastore.
@@ -146,7 +146,7 @@ module Google
146
146
  value.rewind
147
147
  v.blob_value = value.read.force_encoding("ASCII-8BIT")
148
148
  else
149
- fail Google::Cloud::Datastore::PropertyError,
149
+ raise Google::Cloud::Datastore::PropertyError,
150
150
  "A property of type #{value.class} is not supported."
151
151
  end
152
152
  v
@@ -38,19 +38,19 @@ module Google
38
38
  # datastore.project_id #=> "my-todo-project"
39
39
  #
40
40
  class Credentials < Google::Auth::Credentials
41
- SCOPE = ["https://www.googleapis.com/auth/datastore"]
42
- PATH_ENV_VARS = %w(DATASTORE_CREDENTIALS
41
+ SCOPE = ["https://www.googleapis.com/auth/datastore"].freeze
42
+ PATH_ENV_VARS = %w[DATASTORE_CREDENTIALS
43
43
  DATASTORE_KEYFILE
44
44
  GOOGLE_CLOUD_CREDENTIALS
45
45
  GOOGLE_CLOUD_KEYFILE
46
- GCLOUD_KEYFILE)
47
- JSON_ENV_VARS = %w(DATASTORE_CREDENTIALS_JSON
46
+ GCLOUD_KEYFILE].freeze
47
+ JSON_ENV_VARS = %w[DATASTORE_CREDENTIALS_JSON
48
48
  DATASTORE_KEYFILE_JSON
49
49
  GOOGLE_CLOUD_CREDENTIALS_JSON
50
50
  GOOGLE_CLOUD_KEYFILE_JSON
51
- GCLOUD_KEYFILE_JSON)
51
+ GCLOUD_KEYFILE_JSON].freeze
52
52
  DEFAULT_PATHS = \
53
- ["~/.config/gcloud/application_default_credentials.json"]
53
+ ["~/.config/gcloud/application_default_credentials.json"].freeze
54
54
  end
55
55
  end
56
56
  end
@@ -13,7 +13,6 @@
13
13
  # limitations under the License.
14
14
 
15
15
 
16
- require "google/cloud/env"
17
16
  require "google/cloud/datastore/convert"
18
17
  require "google/cloud/datastore/credentials"
19
18
  require "google/cloud/datastore/service"
@@ -82,17 +81,7 @@ module Google
82
81
  def project_id
83
82
  service.project
84
83
  end
85
- alias_method :project, :project_id
86
-
87
- ##
88
- # @private Default project_id.
89
- def self.default_project_id
90
- ENV["DATASTORE_DATASET"] ||
91
- ENV["DATASTORE_PROJECT"] ||
92
- ENV["GOOGLE_CLOUD_PROJECT"] ||
93
- ENV["GCLOUD_PROJECT"] ||
94
- Google::Cloud.env.project_id
95
- end
84
+ alias project project_id
96
85
 
97
86
  ##
98
87
  # Generate IDs for a Key before creating an entity.
@@ -112,12 +101,11 @@ module Google
112
101
  #
113
102
  def allocate_ids incomplete_key, count = 1
114
103
  if incomplete_key.complete?
115
- fail Google::Cloud::Datastore::KeyError,
116
- "An incomplete key must be provided."
104
+ raise Datastore::KeyError, "An incomplete key must be provided."
117
105
  end
118
106
 
119
107
  ensure_service!
120
- incomplete_keys = count.times.map { incomplete_key.to_grpc }
108
+ incomplete_keys = Array.new(count) { incomplete_key.to_grpc }
121
109
  allocate_res = service.allocate_ids(*incomplete_keys)
122
110
  allocate_res.keys.map { |key| Key.from_grpc key }
123
111
  end
@@ -177,7 +165,7 @@ module Google
177
165
  def save *entities
178
166
  commit { |c| c.save(*entities) }
179
167
  end
180
- alias_method :upsert, :save
168
+ alias upsert save
181
169
 
182
170
  ##
183
171
  # Insert one or more entities to the Datastore. An InvalidArgumentError
@@ -353,7 +341,7 @@ module Google
353
341
  end
354
342
  find_all(key, consistency: consistency).first
355
343
  end
356
- alias_method :get, :find
344
+ alias get find
357
345
 
358
346
  ##
359
347
  # Retrieve the entities for the provided keys. The order of results is
@@ -387,7 +375,7 @@ module Google
387
375
  consistency: consistency)
388
376
  LookupResults.from_grpc lookup_res, service, consistency
389
377
  end
390
- alias_method :lookup, :find_all
378
+ alias lookup find_all
391
379
 
392
380
  ##
393
381
  # Retrieve entities specified by a Query.
@@ -455,7 +443,7 @@ module Google
455
443
  def run query, namespace: nil, consistency: nil
456
444
  ensure_service!
457
445
  unless query.is_a?(Query) || query.is_a?(GqlQuery)
458
- fail ArgumentError, "Cannot run a #{query.class} object."
446
+ raise ArgumentError, "Cannot run a #{query.class} object."
459
447
  end
460
448
  check_consistency! consistency
461
449
  query_res = service.run_query query.to_grpc, namespace,
@@ -463,7 +451,7 @@ module Google
463
451
  QueryResults.from_grpc query_res, service, namespace,
464
452
  query.to_grpc.dup
465
453
  end
466
- alias_method :run_query, :run
454
+ alias run_query run
467
455
 
468
456
  ##
469
457
  # Creates a Datastore Transaction.
@@ -557,10 +545,10 @@ module Google
557
545
  # Create new transaction and retry the block
558
546
  tx = Transaction.new service, previous_transaction: tx.id
559
547
  retry
560
- rescue
548
+ rescue StandardError
561
549
  begin
562
550
  tx.rollback
563
- rescue
551
+ rescue StandardError
564
552
  raise TransactionError,
565
553
  "Transaction failed to commit and rollback."
566
554
  end
@@ -614,17 +602,17 @@ module Google
614
602
  begin
615
603
  yield tx
616
604
  tx.commit
617
- rescue
605
+ rescue StandardError
618
606
  begin
619
607
  tx.rollback
620
- rescue
608
+ rescue StandardError
621
609
  raise TransactionError,
622
610
  "Transaction failed to commit and rollback."
623
611
  end
624
612
  raise TransactionError, "Transaction failed to commit."
625
613
  end
626
614
  end
627
- alias_method :snapshot, :read_only_transaction
615
+ alias snapshot read_only_transaction
628
616
 
629
617
  ##
630
618
  # Create a new Query instance. This is a convenience method to make the
@@ -868,11 +856,11 @@ module Google
868
856
  entity = Entity.new
869
857
 
870
858
  # Set the key
871
- if key_or_path.flatten.first.is_a? Google::Cloud::Datastore::Key
872
- entity.key = key_or_path.flatten.first
873
- else
874
- entity.key = key key_or_path, project: project, namespace: namespace
875
- end
859
+ entity.key = if key_or_path.flatten.first.is_a? Datastore::Key
860
+ key_or_path.flatten.first
861
+ else
862
+ key key_or_path, project: project, namespace: namespace
863
+ end
876
864
 
877
865
  yield entity if block_given?
878
866
 
@@ -885,7 +873,7 @@ module Google
885
873
  # @private Raise an error unless an active connection to the service is
886
874
  # available.
887
875
  def ensure_service!
888
- fail "Must have active connection to service" unless service
876
+ raise "Must have active connection to service" unless service
889
877
  end
890
878
 
891
879
  def validate_deadline deadline
@@ -895,10 +883,12 @@ module Google
895
883
  end
896
884
 
897
885
  def check_consistency! consistency
898
- fail(ArgumentError,
899
- format("Consistency must be :eventual or :strong, not %s.",
900
- consistency.inspect)
901
- ) unless [:eventual, :strong, nil].include? consistency
886
+ return if [:eventual, :strong, nil].include? consistency
887
+
888
+ error_msg = format("Consistency must be :eventual or :strong, " \
889
+ "not %<bad_consistency>s.",
890
+ bad_consistency: consistency.inspect)
891
+ raise ArgumentError, error_msg
902
892
  end
903
893
  end
904
894
  end
@@ -110,7 +110,8 @@ module Google
110
110
  ensure_service!
111
111
  lookup_res = @service.lookup(
112
112
  *Array(@deferred).flatten.map(&:to_grpc),
113
- consistency: @consistency, transaction: @transaction)
113
+ consistency: @consistency, transaction: @transaction
114
+ )
114
115
  self.class.from_grpc lookup_res, @service, @consistency
115
116
  end
116
117
 
@@ -199,18 +200,8 @@ module Google
199
200
  end
200
201
  end
201
202
 
202
- protected
203
-
204
- ##
205
- # @private Raise an error unless an active connection to the service
206
- # is available.
207
- def ensure_service!
208
- msg = "Must have active connection to datastore service to get next"
209
- fail msg if @service.nil?
210
- end
211
-
212
203
  ##
213
- # Convenience method to convert GRPC entities to google-cloud
204
+ # @private Convenience method to convert GRPC entities to google-cloud
214
205
  # entities.
215
206
  def self.to_gcloud_entities grpc_entity_results
216
207
  # Entities are nested in an object.
@@ -221,11 +212,22 @@ module Google
221
212
  end
222
213
 
223
214
  ##
224
- # Convenience method to convert GRPC keys to google-cloud keys.
215
+ # @private Convenience method to convert GRPC keys to google-cloud
216
+ # keys.
225
217
  def self.to_gcloud_keys grpc_keys
226
218
  # Keys are not nested in an object like entities are.
227
219
  Array(grpc_keys).map { |key| Key.from_grpc key }
228
220
  end
221
+
222
+ protected
223
+
224
+ ##
225
+ # @private Raise an error unless an active connection to the service
226
+ # is available.
227
+ def ensure_service!
228
+ msg = "Must have active connection to datastore service to get next"
229
+ raise msg if @service.nil?
230
+ end
229
231
  end
230
232
  end
231
233
  end
@@ -59,7 +59,7 @@ module Google
59
59
  #
60
60
  # @return [Google::Cloud::Datastore::Cursor]
61
61
  attr_reader :end_cursor
62
- alias_method :cursor, :end_cursor
62
+ alias cursor end_cursor
63
63
 
64
64
  ##
65
65
  # The state of the query after the current batch.
@@ -157,6 +157,7 @@ module Google
157
157
  return nil if end_cursor.nil?
158
158
  ensure_service!
159
159
  query.start_cursor = cursor.to_grpc # should always be a Cursor...
160
+ query.offset = 0 # Never carry an offset across batches
160
161
  query_res = service.run_query query, namespace
161
162
  self.class.from_grpc query_res, service, namespace, query
162
163
  end
@@ -378,7 +379,7 @@ module Google
378
379
  # is available.
379
380
  def ensure_service!
380
381
  msg = "Must have active connection to datastore service to get next"
381
- fail msg if @service.nil? || @query.nil?
382
+ raise msg if @service.nil? || @query.nil?
382
383
  end
383
384
  end
384
385
  end
@@ -267,12 +267,14 @@ module Google
267
267
  #
268
268
  # task = datastore.find "Task", "sampleTask"
269
269
  # task.persisted? #=> true
270
- # task.key = datastore.key "Task" #=> raise RuntimeError
270
+ # # Because the entity is persisted, the following would raise
271
+ # # task.key = datastore.key "Task"
271
272
  # task.key.frozen? #=> true
272
- # task.key.id = 9876543221 #=> raise RuntimeError
273
+ # # Because the key is frozen, the following would raise
274
+ # # task.key.id = 9876543221
273
275
  #
274
276
  def key= new_key
275
- fail "This entity's key is immutable." if persisted?
277
+ raise "This entity's key is immutable." if persisted?
276
278
  @key = new_key
277
279
  end
278
280
 
@@ -160,11 +160,13 @@ module Google
160
160
  if value.is_a? Google::Cloud::Datastore::Cursor
161
161
  @grpc.named_bindings[name.to_s] = \
162
162
  Google::Datastore::V1::GqlQueryParameter.new(
163
- cursor: value.to_grpc)
163
+ cursor: value.to_grpc
164
+ )
164
165
  else
165
166
  @grpc.named_bindings[name.to_s] = \
166
167
  Google::Datastore::V1::GqlQueryParameter.new(
167
- value: Convert.to_value(value))
168
+ value: Convert.to_value(value)
169
+ )
168
170
  end
169
171
  end
170
172
  end
@@ -209,11 +211,13 @@ module Google
209
211
  if value.is_a? Google::Cloud::Datastore::Cursor
210
212
  @grpc.positional_bindings << \
211
213
  Google::Datastore::V1::GqlQueryParameter.new(
212
- cursor: value.to_grpc)
214
+ cursor: value.to_grpc
215
+ )
213
216
  else
214
217
  @grpc.positional_bindings << \
215
218
  Google::Datastore::V1::GqlQueryParameter.new(
216
- value: Convert.to_value(value))
219
+ value: Convert.to_value(value)
220
+ )
217
221
  end
218
222
  end
219
223
  end
@@ -64,10 +64,10 @@ module Google
64
64
  # task.key.project #=> "my-todo-project"
65
65
  #
66
66
  attr_accessor :project
67
- alias_method :project_id, :project
68
- alias_method :project_id=, :project=
69
- alias_method :dataset_id, :project
70
- alias_method :dataset_id=, :project=
67
+ alias project_id project
68
+ alias project_id= project=
69
+ alias dataset_id project
70
+ alias dataset_id= project=
71
71
 
72
72
  ##
73
73
  # The namespace of the Key.
@@ -282,7 +282,8 @@ module Google
282
282
  grpc = Google::Datastore::V1::Key.new(path: grpc_path)
283
283
  if project || namespace
284
284
  grpc.partition_id = Google::Datastore::V1::PartitionId.new(
285
- project_id: project.to_s, namespace_id: namespace.to_s)
285
+ project_id: project.to_s, namespace_id: namespace.to_s
286
+ )
286
287
  end
287
288
  grpc
288
289
  end
@@ -38,14 +38,14 @@ module Google
38
38
  key = ensure_key_type key
39
39
  @hash[key]
40
40
  end
41
- alias_method :read, :[]
41
+ alias read []
42
42
 
43
43
  def []= key, value
44
44
  key = ensure_key_type key
45
45
  value = ensure_value_type value
46
46
  @hash[key] = value
47
47
  end
48
- alias_method :write, :[]=
48
+ alias write []=
49
49
 
50
50
  def exist? key
51
51
  key = ensure_key_type key
@@ -70,7 +70,7 @@ module Google
70
70
  def to_h
71
71
  @hash.dup
72
72
  end
73
- alias_method :to_hash, :to_h
73
+ alias to_hash to_h
74
74
 
75
75
  def to_grpc
76
76
  # Convert to Hash with Google::Datastore::V1::Value values.
@@ -89,7 +89,7 @@ module Google
89
89
  # otherwise a PropertyError is raised.
90
90
  def ensure_key_type key
91
91
  return key.to_s if key.respond_to? :to_s
92
- fail "Property key #{key} must be a String."
92
+ raise "Property key #{key} must be a String."
93
93
  end
94
94
 
95
95
  # rubocop:disable all
@@ -120,7 +120,7 @@ module Google
120
120
  elsif defined?(BigDecimal) && BigDecimal === value
121
121
  return value
122
122
  end
123
- fail PropertyError, "A property of type #{value.class} is not supported."
123
+ raise PropertyError, "A property of type #{value.class} is not supported."
124
124
  end
125
125
  # rubocop:enable all
126
126
  end
@@ -84,7 +84,8 @@ module Google
84
84
  def kind *kinds
85
85
  kinds.each do |kind|
86
86
  grpc_kind = Google::Datastore::V1::KindExpression.new(
87
- name: kind)
87
+ name: kind
88
+ )
88
89
  @grpc.kind << grpc_kind
89
90
  end
90
91
 
@@ -185,7 +186,8 @@ module Google
185
186
  Google::Datastore::V1::Filter.new(
186
187
  property_filter: Google::Datastore::V1::PropertyFilter.new(
187
188
  property: Google::Datastore::V1::PropertyReference.new(
188
- name: name),
189
+ name: name
190
+ ),
189
191
  op: Convert.to_prop_filter_op(operator),
190
192
  value: Convert.to_value(value)
191
193
  )
@@ -193,7 +195,7 @@ module Google
193
195
 
194
196
  self
195
197
  end
196
- alias_method :filter, :where
198
+ alias filter where
197
199
 
198
200
  ##
199
201
  # Add a filter for entities that inherit from a key.
@@ -273,7 +275,8 @@ module Google
273
275
  def order name, direction = :asc
274
276
  @grpc.order << Google::Datastore::V1::PropertyOrder.new(
275
277
  property: Google::Datastore::V1::PropertyReference.new(
276
- name: name),
278
+ name: name
279
+ ),
277
280
  direction: prop_order_direction(direction)
278
281
  )
279
282
 
@@ -342,12 +345,12 @@ module Google
342
345
  elsif cursor.is_a? String
343
346
  @grpc.start_cursor = Convert.decode_bytes cursor
344
347
  else
345
- fail ArgumentError, "Can't set a cursor using a #{cursor.class}."
348
+ raise ArgumentError, "Can't set a cursor using a #{cursor.class}."
346
349
  end
347
350
 
348
351
  self
349
352
  end
350
- alias_method :cursor, :start
353
+ alias cursor start
351
354
 
352
355
  ##
353
356
  # Retrieve only select properties from the matched entities.
@@ -383,13 +386,15 @@ module Google
383
386
  names.each do |name|
384
387
  grpc_projection = Google::Datastore::V1::Projection.new(
385
388
  property: Google::Datastore::V1::PropertyReference.new(
386
- name: name))
389
+ name: name
390
+ )
391
+ )
387
392
  @grpc.projection << grpc_projection
388
393
  end
389
394
 
390
395
  self
391
396
  end
392
- alias_method :projection, :select
397
+ alias projection select
393
398
 
394
399
  ##
395
400
  # Group results by a list of properties.
@@ -410,13 +415,14 @@ module Google
410
415
  def group_by *names
411
416
  names.each do |name|
412
417
  grpc_property = Google::Datastore::V1::PropertyReference.new(
413
- name: name)
418
+ name: name
419
+ )
414
420
  @grpc.distinct_on << grpc_property
415
421
  end
416
422
 
417
423
  self
418
424
  end
419
- alias_method :distinct_on, :group_by
425
+ alias distinct_on group_by
420
426
 
421
427
  # @private
422
428
  def to_grpc
@@ -95,7 +95,7 @@ module Google
95
95
  end
96
96
  find_all(key).first
97
97
  end
98
- alias_method :get, :find
98
+ alias get find
99
99
 
100
100
  ##
101
101
  # Retrieve the entities for the provided keys. The lookup is run within
@@ -123,7 +123,7 @@ module Google
123
123
  transaction: @id)
124
124
  Dataset::LookupResults.from_grpc lookup_res, service, nil, @id
125
125
  end
126
- alias_method :lookup, :find_all
126
+ alias lookup find_all
127
127
 
128
128
  ##
129
129
  # Retrieve entities specified by a Query. The query is run within the
@@ -148,27 +148,27 @@ module Google
148
148
  def run query, namespace: nil
149
149
  ensure_service!
150
150
  unless query.is_a?(Query) || query.is_a?(GqlQuery)
151
- fail ArgumentError, "Cannot run a #{query.class} object."
151
+ raise ArgumentError, "Cannot run a #{query.class} object."
152
152
  end
153
153
  query_res = service.run_query query.to_grpc, namespace,
154
154
  transaction: @id
155
155
  Dataset::QueryResults.from_grpc query_res, service, namespace,
156
156
  query.to_grpc.dup
157
157
  end
158
- alias_method :run_query, :run
158
+ alias run_query run
159
159
 
160
160
  ##
161
161
  # Begins a transaction.
162
162
  # This method is run when a new ReadOnlyTransaction is created.
163
163
  #
164
164
  def start
165
- fail TransactionError, "Transaction already opened." unless @id.nil?
165
+ raise TransactionError, "Transaction already opened." unless @id.nil?
166
166
 
167
167
  ensure_service!
168
168
  tx_res = service.begin_transaction read_only: true
169
169
  @id = tx_res.transaction
170
170
  end
171
- alias_method :begin_transaction, :start
171
+ alias begin_transaction start
172
172
 
173
173
  ##
174
174
  # Commits the transaction.
@@ -190,8 +190,9 @@ module Google
190
190
  # tx.commit
191
191
  #
192
192
  def commit
193
- fail TransactionError,
194
- "Cannot commit when not in a transaction." if @id.nil?
193
+ if @id.nil?
194
+ raise TransactionError, "Cannot commit when not in a transaction."
195
+ end
195
196
 
196
197
  ensure_service!
197
198
 
@@ -220,7 +221,7 @@ module Google
220
221
  #
221
222
  def rollback
222
223
  if @id.nil?
223
- fail TransactionError, "Cannot rollback when not in a transaction."
224
+ raise TransactionError, "Cannot rollback when not in a transaction."
224
225
  end
225
226
 
226
227
  ensure_service!
@@ -241,7 +242,7 @@ module Google
241
242
  # @private Raise an error unless an active connection to the service is
242
243
  # available.
243
244
  def ensure_service!
244
- fail "Must have active connection to service" unless service
245
+ raise "Must have active connection to service" unless service
245
246
  end
246
247
  end
247
248
  end
@@ -58,7 +58,8 @@ module Google
58
58
  timeout: timeout,
59
59
  client_config: client_config,
60
60
  lib_name: "gccl",
61
- lib_version: Google::Cloud::Datastore::VERSION)
61
+ lib_version: Google::Cloud::Datastore::VERSION
62
+ )
62
63
  end
63
64
  attr_accessor :mocked_service
64
65
 
@@ -95,8 +96,11 @@ module Google
95
96
  query = nil
96
97
  end
97
98
  read_options = generate_read_options consistency, transaction
98
- partition_id = Google::Datastore::V1::PartitionId.new(
99
- namespace_id: namespace) if namespace
99
+ if namespace
100
+ partition_id = Google::Datastore::V1::PartitionId.new(
101
+ namespace_id: namespace
102
+ )
103
+ end
100
104
 
101
105
  execute do
102
106
  service.run_query project,
@@ -158,13 +162,16 @@ module Google
158
162
  def generate_read_options consistency, transaction
159
163
  if consistency == :eventual
160
164
  return Google::Datastore::V1::ReadOptions.new(
161
- read_consistency: :EVENTUAL)
165
+ read_consistency: :EVENTUAL
166
+ )
162
167
  elsif consistency == :strong
163
- return Google::Datastore::V1::ReadOptions.new(
164
- read_consistency: :STRONG)
168
+ return Google::Datastore::V1::ReadOptions.new(
169
+ read_consistency: :STRONG
170
+ )
165
171
  elsif transaction
166
- return Google::Datastore::V1::ReadOptions.new(
167
- transaction: transaction)
172
+ return Google::Datastore::V1::ReadOptions.new(
173
+ transaction: transaction
174
+ )
168
175
  end
169
176
  nil
170
177
  end
@@ -85,7 +85,7 @@ module Google
85
85
  # Do not save yet
86
86
  entities
87
87
  end
88
- alias_method :upsert, :save
88
+ alias upsert save
89
89
 
90
90
  ##
91
91
  # Insert entities in a transaction. An InvalidArgumentError will raised
@@ -194,7 +194,7 @@ module Google
194
194
  end
195
195
  find_all(key).first
196
196
  end
197
- alias_method :get, :find
197
+ alias get find
198
198
 
199
199
  ##
200
200
  # Retrieve the entities for the provided keys. The lookup is run within
@@ -219,7 +219,7 @@ module Google
219
219
  transaction: @id)
220
220
  LookupResults.from_grpc lookup_res, service, nil, @id
221
221
  end
222
- alias_method :lookup, :find_all
222
+ alias lookup find_all
223
223
 
224
224
  ##
225
225
  # Retrieve entities specified by a Query. The query is run within the
@@ -254,27 +254,27 @@ module Google
254
254
  def run query, namespace: nil
255
255
  ensure_service!
256
256
  unless query.is_a?(Query) || query.is_a?(GqlQuery)
257
- fail ArgumentError, "Cannot run a #{query.class} object."
257
+ raise ArgumentError, "Cannot run a #{query.class} object."
258
258
  end
259
259
  query_res = service.run_query query.to_grpc, namespace,
260
260
  transaction: @id
261
261
  QueryResults.from_grpc query_res, service, namespace,
262
262
  query.to_grpc.dup
263
263
  end
264
- alias_method :run_query, :run
264
+ alias run_query run
265
265
 
266
266
  ##
267
267
  # Begins a transaction.
268
268
  # This method is run when a new Transaction is created.
269
269
  def start
270
- fail TransactionError, "Transaction already opened." unless @id.nil?
270
+ raise TransactionError, "Transaction already opened." unless @id.nil?
271
271
 
272
272
  ensure_service!
273
273
  tx_res = service.begin_transaction \
274
274
  previous_transaction: @previous_transaction
275
275
  @id = tx_res.transaction
276
276
  end
277
- alias_method :begin_transaction, :start
277
+ alias begin_transaction start
278
278
 
279
279
  ##
280
280
  # Commits a transaction.
@@ -320,8 +320,9 @@ module Google
320
320
  # end
321
321
  #
322
322
  def commit
323
- fail TransactionError,
324
- "Cannot commit when not in a transaction." if @id.nil?
323
+ if @id.nil?
324
+ raise TransactionError, "Cannot commit when not in a transaction."
325
+ end
325
326
 
326
327
  yield @commit if block_given?
327
328
 
@@ -365,7 +366,7 @@ module Google
365
366
  # end
366
367
  def rollback
367
368
  if @id.nil?
368
- fail TransactionError, "Cannot rollback when not in a transaction."
369
+ raise TransactionError, "Cannot rollback when not in a transaction."
369
370
  end
370
371
 
371
372
  ensure_service!
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Datastore
19
- VERSION = "1.3.0"
19
+ VERSION = "1.4.0".freeze
20
20
  end
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-datastore
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-12-19 00:00:00.000000000 Z
12
+ date: 2018-02-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-cloud-core
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '1.1'
20
+ version: '1.2'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '1.1'
27
+ version: '1.2'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: google-gax
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -127,16 +127,16 @@ dependencies:
127
127
  name: rubocop
128
128
  requirement: !ruby/object:Gem::Requirement
129
129
  requirements:
130
- - - "<="
130
+ - - "~>"
131
131
  - !ruby/object:Gem::Version
132
- version: 0.35.1
132
+ version: 0.50.0
133
133
  type: :development
134
134
  prerelease: false
135
135
  version_requirements: !ruby/object:Gem::Requirement
136
136
  requirements:
137
- - - "<="
137
+ - - "~>"
138
138
  - !ruby/object:Gem::Version
139
- version: 0.35.1
139
+ version: 0.50.0
140
140
  - !ruby/object:Gem::Dependency
141
141
  name: simplecov
142
142
  requirement: !ruby/object:Gem::Requirement
@@ -241,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
241
241
  version: '0'
242
242
  requirements: []
243
243
  rubyforge_project:
244
- rubygems_version: 2.7.3
244
+ rubygems_version: 2.7.6
245
245
  signing_key:
246
246
  specification_version: 4
247
247
  summary: API Client library for Google Cloud Datastore