google-cloud-firestore 2.4.1 → 2.5.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: 3947e279213a82502325fd1f9245f72c9b5d3fa837907608f6bdd62bff31e69f
4
- data.tar.gz: 849fc8dc2f763b24334d4accdc2ee4196059c429d273f3f661bf50d81a6d9774
3
+ metadata.gz: 9faa52fed532effb0c8cb260b4159cfed65ba53a790f1c2451f5a610f46fa551
4
+ data.tar.gz: 8e2cbe9b830a1e4c46b49080cfa717a9e6e9f8901848aea6a905edd1d3234544
5
5
  SHA512:
6
- metadata.gz: 8d2a6c39cc4b321a2561b5ae50928eaec7a3acfafe5fec62a7383d5c3dc77c60ba96f81c2c027bcfe46be6f8ab02c0f76f93afd0dd5ab5bb7fdea9e141a33fe4
7
- data.tar.gz: 70b462d91bd613ee0a5c333653dc096c28878d4bf28eacc6282c4edf57123985eeec8eee4d98af24aba334ea824e2e37d2add104aa8e32c26c7668c7dc62df4f
6
+ metadata.gz: 94c1832275adb689e4394d03fd724dd39240eedb9fbfad132f4217ea97b1d6076cc0b8e0b846eec2a1afdf1180ffd2e981c5d5ecef12e6aaf11a04fe52460b44
7
+ data.tar.gz: c9b0c729751b0ed24ff39be1e56905da26bec6af30410e1112325482b07b888f3f1c07e60c5b1bc7bd8e90b58a710f0cb31e4a0d6181179c69d5b23267d5904f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Release History
2
2
 
3
+ ### 2.5.0 / 2021-03-10
4
+
5
+ #### Features
6
+
7
+ * Drop support for Ruby 2.4 and add support for Ruby 3.0
8
+
3
9
  ### 2.4.1 / 2021-01-06
4
10
 
5
11
  #### Bug Fixes
data/CONTRIBUTING.md CHANGED
@@ -24,7 +24,7 @@ be able to accept your pull requests.
24
24
  In order to use the google-cloud-firestore console and run the project's tests,
25
25
  there is a small amount of setup:
26
26
 
27
- 1. Install Ruby. google-cloud-firestore requires Ruby 2.4+. You may choose to
27
+ 1. Install Ruby. google-cloud-firestore requires Ruby 2.5+. You may choose to
28
28
  manage your Ruby and gem installations with [RVM](https://rvm.io/),
29
29
  [rbenv](https://github.com/rbenv/rbenv), or
30
30
  [chruby](https://github.com/postmodern/chruby).
data/LOGGING.md CHANGED
@@ -3,7 +3,7 @@
3
3
  To enable logging for this library, set the logger for the underlying
4
4
  [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library. The logger
5
5
  that you set may be a Ruby stdlib
6
- [`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html) as
6
+ [`Logger`](https://ruby-doc.org/stdlib/libdoc/logger/rdoc/Logger.html) as
7
7
  shown below, or a
8
8
  [`Google::Cloud::Logging::Logger`](https://googleapis.dev/ruby/google-cloud-logging/latest)
9
9
  that will write logs to [Stackdriver
@@ -322,8 +322,7 @@ module Google
322
322
 
323
323
  doc_path = coalesce_doc_path_argument doc
324
324
 
325
- @writes << Convert.write_for_update(doc_path, data,
326
- update_time: update_time)
325
+ @writes << Convert.write_for_update(doc_path, data, update_time: update_time)
327
326
 
328
327
  nil
329
328
  end
@@ -100,11 +100,11 @@ module Google
100
100
  # puts col.collection_id
101
101
  # end
102
102
  #
103
- def cols
103
+ def cols &block
104
104
  ensure_service!
105
105
  grpc = service.list_collections "#{path}/documents"
106
106
  cols_enum = CollectionReferenceList.from_grpc(grpc, self, "#{path}/documents").all
107
- cols_enum.each { |c| yield c } if block_given?
107
+ cols_enum.each(&block) if block_given?
108
108
  cols_enum
109
109
  end
110
110
  alias collections cols
@@ -256,7 +256,7 @@ module Google
256
256
  ensure_service!
257
257
 
258
258
  unless block_given?
259
- return enum_for :get_all, docs, field_mask: field_mask
259
+ return enum_for :get_all, *docs, field_mask: field_mask
260
260
  end
261
261
 
262
262
  doc_paths = Array(docs).flatten.map do |doc_path|
@@ -634,9 +634,9 @@ module Google
634
634
  commit_return = transaction.commit
635
635
  # Conditional return value, depending on truthy commit_response
636
636
  commit_response ? commit_return : transaction_return
637
- rescue Google::Cloud::UnavailableError => err
637
+ rescue Google::Cloud::UnavailableError => e
638
638
  # Re-raise if retried more than the max
639
- raise err if backoff[:current] > backoff[:max]
639
+ raise e if backoff[:current] > backoff[:max]
640
640
 
641
641
  # Sleep with incremental backoff before restarting
642
642
  sleep backoff[:delay]
@@ -649,18 +649,18 @@ module Google
649
649
  transaction = Transaction.from_client \
650
650
  self, previous_transaction: transaction.transaction_id
651
651
  retry
652
- rescue Google::Cloud::InvalidArgumentError => err
652
+ rescue Google::Cloud::InvalidArgumentError => e
653
653
  # Return if a previous call was retried but ultimately succeeded
654
- return nil if backoff[:current] > 0
654
+ return nil if backoff[:current].positive?
655
655
 
656
656
  # Re-raise error.
657
- raise err
658
- rescue StandardError => err
657
+ raise e
658
+ rescue StandardError => e
659
659
  # Rollback transaction when handling unexpected error
660
660
  transaction.rollback rescue nil
661
661
 
662
662
  # Re-raise error.
663
- raise err
663
+ raise e
664
664
  end
665
665
  end
666
666
 
@@ -90,17 +90,17 @@ module Google
90
90
  # collection_reference.collection_id
91
91
  # end
92
92
  #
93
- def all request_limit: nil
93
+ def all request_limit: nil, &block
94
94
  request_limit = request_limit.to_i if request_limit
95
95
  unless block_given?
96
96
  return enum_for :all, request_limit: request_limit
97
97
  end
98
98
  results = self
99
99
  loop do
100
- results.each { |r| yield r }
100
+ results.each(&block)
101
101
  if request_limit
102
102
  request_limit -= 1
103
- break if request_limit < 0
103
+ break if request_limit.negative?
104
104
  end
105
105
  break unless results.next?
106
106
  results = results.next
@@ -30,7 +30,6 @@ module Google
30
30
  # rubocop:disable Metrics/MethodLength
31
31
  # rubocop:disable Metrics/ModuleLength
32
32
  # rubocop:disable Metrics/PerceivedComplexity
33
- # rubocop:disable Style/CaseEquality
34
33
  module ClassMethods
35
34
  def time_to_timestamp time
36
35
  return nil if time.nil?
@@ -263,10 +262,8 @@ module Google
263
262
  # Restore delete paths
264
263
  field_paths += delete_field_paths_and_values.keys
265
264
 
266
- if data.empty? && !allow_empty
267
- if field_paths_and_values.empty? && delete_field_paths_and_values.empty?
268
- raise ArgumentError, "data required for set with merge"
269
- end
265
+ if data.empty? && !allow_empty && field_paths_and_values.empty? && delete_field_paths_and_values.empty?
266
+ raise ArgumentError, "data required for set with merge"
270
267
  end
271
268
 
272
269
  doc = Google::Cloud::Firestore::V1::Document.new(
@@ -374,12 +371,13 @@ module Google
374
371
  def field_value_nested? obj, field_value_type = nil
375
372
  return obj if obj.is_a?(FieldValue) && (field_value_type.nil? || obj.type == field_value_type)
376
373
 
377
- if obj.is_a? Array
374
+ case obj
375
+ when Array
378
376
  obj.each do |o|
379
377
  val = field_value_nested? o, field_value_type
380
378
  return val if val
381
379
  end
382
- elsif obj.is_a? Hash
380
+ when Hash
383
381
  obj.each do |_k, v|
384
382
  val = field_value_nested? v, field_value_type
385
383
  return val if val
@@ -531,8 +529,8 @@ module Google
531
529
  end
532
530
 
533
531
  START_FIELD_PATH_CHARS = /\A[a-zA-Z_]/.freeze
534
- INVALID_FIELD_PATH_CHARS = %r{[\~\*/\[\]]}.freeze
535
- ESCAPED_FIELD_PATH = /\A\`(.*)\`\z/.freeze
532
+ INVALID_FIELD_PATH_CHARS = %r{[~*/\[\]]}.freeze
533
+ ESCAPED_FIELD_PATH = /\A`(.*)`\z/.freeze
536
534
 
537
535
  def build_hash_from_field_paths_and_values pairs
538
536
  pairs.each do |field_path, _value|
@@ -567,32 +565,33 @@ module Google
567
565
  end
568
566
 
569
567
  def to_field_transform field_path, field_value
570
- if field_value.type == :server_time
568
+ case field_value.type
569
+ when :server_time
571
570
  Google::Cloud::Firestore::V1::DocumentTransform::FieldTransform.new(
572
571
  field_path: field_path.formatted_string,
573
572
  set_to_server_value: :REQUEST_TIME
574
573
  )
575
- elsif field_value.type == :array_union
574
+ when :array_union
576
575
  Google::Cloud::Firestore::V1::DocumentTransform::FieldTransform.new(
577
576
  field_path: field_path.formatted_string,
578
577
  append_missing_elements: raw_to_value(Array(field_value.value)).array_value
579
578
  )
580
- elsif field_value.type == :array_delete
579
+ when :array_delete
581
580
  Google::Cloud::Firestore::V1::DocumentTransform::FieldTransform.new(
582
581
  field_path: field_path.formatted_string,
583
582
  remove_all_from_array: raw_to_value(Array(field_value.value)).array_value
584
583
  )
585
- elsif field_value.type == :increment
584
+ when :increment
586
585
  Google::Cloud::Firestore::V1::DocumentTransform::FieldTransform.new(
587
586
  field_path: field_path.formatted_string,
588
587
  increment: raw_to_value(field_value.value)
589
588
  )
590
- elsif field_value.type == :maximum
589
+ when :maximum
591
590
  Google::Cloud::Firestore::V1::DocumentTransform::FieldTransform.new(
592
591
  field_path: field_path.formatted_string,
593
592
  maximum: raw_to_value(field_value.value)
594
593
  )
595
- elsif field_value.type == :minimum
594
+ when :minimum
596
595
  Google::Cloud::Firestore::V1::DocumentTransform::FieldTransform.new(
597
596
  field_path: field_path.formatted_string,
598
597
  minimum: raw_to_value(field_value.value)
@@ -611,7 +610,6 @@ module Google
611
610
  # rubocop:enable Metrics/MethodLength
612
611
  # rubocop:enable Metrics/ModuleLength
613
612
  # rubocop:enable Metrics/PerceivedComplexity
614
- # rubocop:enable Style/CaseEquality
615
613
  end
616
614
  end
617
615
  end
@@ -90,11 +90,11 @@ module Google
90
90
  # puts col.collection_id
91
91
  # end
92
92
  #
93
- def cols
93
+ def cols &block
94
94
  ensure_service!
95
95
  grpc = service.list_collections path
96
96
  cols_enum = CollectionReferenceList.from_grpc(grpc, client, path).all
97
- cols_enum.each { |c| yield c } if block_given?
97
+ cols_enum.each(&block) if block_given?
98
98
  cols_enum
99
99
  end
100
100
  alias collections cols
@@ -86,8 +86,7 @@ module Google
86
86
  def next
87
87
  return nil unless next?
88
88
  ensure_client!
89
- options = { token: token, max: @max }
90
- grpc = @client.service.list_documents @parent, @collection_id, options
89
+ grpc = @client.service.list_documents @parent, @collection_id, token: token, max: @max
91
90
  self.class.from_grpc grpc, @client, @parent, @collection_id, @max
92
91
  end
93
92
 
@@ -143,17 +142,17 @@ module Google
143
142
  # puts doc_ref.document_id
144
143
  # end
145
144
  #
146
- def all request_limit: nil
145
+ def all request_limit: nil, &block
147
146
  request_limit = request_limit.to_i if request_limit
148
147
  unless block_given?
149
148
  return enum_for :all, request_limit: request_limit
150
149
  end
151
150
  results = self
152
151
  loop do
153
- results.each { |r| yield r }
152
+ results.each(&block)
154
153
  if request_limit
155
154
  request_limit -= 1
156
- break if request_limit < 0
155
+ break if request_limit.negative?
157
156
  end
158
157
  break unless results.next?
159
158
  results = results.next
@@ -210,14 +210,14 @@ module Google
210
210
  protected
211
211
 
212
212
  START_FIELD_PATH_CHARS = /\A[a-zA-Z_]/.freeze
213
- INVALID_FIELD_PATH_CHARS = %r{[\~\*\/\[\]]}.freeze
213
+ INVALID_FIELD_PATH_CHARS = %r{[~*/\[\]]}.freeze
214
214
 
215
215
  def escape_field_for_path field
216
216
  field = String field
217
217
 
218
218
  if INVALID_FIELD_PATH_CHARS.match(field) ||
219
219
  field["."] || field["`"] || field["\\"]
220
- escaped_field = field.gsub(/[\`\\]/, "`" => "\\\`", "\\" => "\\\\")
220
+ escaped_field = field.gsub(/[`\\]/, "`" => "\\\`", "\\" => "\\\\")
221
221
  return "`#{escaped_field}`"
222
222
  end
223
223
 
@@ -1010,11 +1010,11 @@ module Google
1010
1010
  }.freeze
1011
1011
  ##
1012
1012
  # @private
1013
- INEQUALITY_FILTERS = %i[
1014
- LESS_THAN
1015
- LESS_THAN_OR_EQUAL
1016
- GREATER_THAN
1017
- GREATER_THAN_OR_EQUAL
1013
+ INEQUALITY_FILTERS = [
1014
+ :LESS_THAN,
1015
+ :LESS_THAN_OR_EQUAL,
1016
+ :GREATER_THAN,
1017
+ :GREATER_THAN_OR_EQUAL
1018
1018
  ].freeze
1019
1019
 
1020
1020
  def value_nil? value
@@ -1031,15 +1031,16 @@ module Google
1031
1031
  value_nil?(value) || value_nan?(value)
1032
1032
  end
1033
1033
 
1034
- def filter name, op, value
1034
+ def filter name, op_key, value
1035
1035
  field = StructuredQuery::FieldReference.new field_path: name.to_s
1036
- operator = FILTER_OPS[op.to_s.downcase]
1037
- raise ArgumentError, "unknown operator #{op}" if operator.nil?
1036
+ operator = FILTER_OPS[op_key.to_s.downcase]
1037
+ raise ArgumentError, "unknown operator #{op_key}" if operator.nil?
1038
1038
 
1039
1039
  if value_unary? value
1040
- operator = if operator == :EQUAL
1040
+ operator = case operator
1041
+ when :EQUAL
1041
1042
  value_nan?(value) ? :IS_NAN : :IS_NULL
1042
- elsif operator == :NOT_EQUAL
1043
+ when :NOT_EQUAL
1043
1044
  value_nan?(value) ? :IS_NOT_NAN : :IS_NOT_NULL
1044
1045
  else
1045
1046
  raise ArgumentError, "can only perform '==' and '!=' comparisons on #{value} values"
@@ -26,7 +26,10 @@ module Google
26
26
  # @private Represents the gRPC Firestore service, including all the API
27
27
  # methods.
28
28
  class Service
29
- attr_accessor :project, :credentials, :timeout, :host
29
+ attr_accessor :project
30
+ attr_accessor :credentials
31
+ attr_accessor :timeout
32
+ attr_accessor :host
30
33
 
31
34
  ##
32
35
  # Creates a new Service instance.
@@ -131,7 +131,7 @@ module Google
131
131
  ensure_service!
132
132
 
133
133
  unless block_given?
134
- return enum_for :get_all, docs, field_mask: field_mask
134
+ return enum_for :get_all, *docs, field_mask: field_mask
135
135
  end
136
136
 
137
137
  doc_paths = Array(docs).flatten.map do |doc_path|
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Firestore
19
- VERSION = "2.4.1".freeze
19
+ VERSION = "2.5.0".freeze
20
20
  end
21
21
  end
22
22
  end
@@ -33,7 +33,8 @@ module Google
33
33
  # make inserting and removing objects much more efficent.
34
34
  class Inventory
35
35
  attr_accessor :current
36
- attr_reader :resume_token, :read_time
36
+ attr_reader :resume_token
37
+ attr_reader :read_time
37
38
 
38
39
  def initialize client, query
39
40
  @client = client
@@ -155,24 +156,24 @@ module Google
155
156
 
156
157
  protected
157
158
 
158
- def query_comparison_proc a, b
159
+ def query_comparison_proc left, right
159
160
  # TODO: Remove this when done benchmarking
160
161
  @comp_proc_counter += 1
161
162
 
162
- return Order.compare_field_values a.ref, b.ref if @query.nil?
163
+ return Order.compare_field_values left.ref, right.ref if @query.nil?
163
164
 
164
165
  @directions ||= @query.query.order_by.map(&:direction)
165
166
 
166
- a_comps = a.query_comparisons_for @query.query
167
- b_comps = b.query_comparisons_for @query.query
168
- @directions.zip(a_comps, b_comps).each do |dir, a_comp, b_comp|
169
- comp = a_comp <=> b_comp
167
+ left_comps = left.query_comparisons_for @query.query
168
+ right_comps = right.query_comparisons_for @query.query
169
+ @directions.zip(left_comps, right_comps).each do |dir, left_comp, right_comp|
170
+ comp = left_comp <=> right_comp
170
171
  comp = 0 - comp if dir == :DESCENDING
171
172
  return comp unless comp.zero?
172
173
  end
173
174
 
174
175
  # Compare paths when everything else is equal
175
- ref_comp = Order.compare_field_values a.ref, b.ref
176
+ ref_comp = Order.compare_field_values left.ref, right.ref
176
177
  ref_comp = 0 - ref_comp if @directions.last == :DESCENDING
177
178
  ref_comp
178
179
  end
@@ -83,7 +83,7 @@ module Google
83
83
  def stop
84
84
  synchronize do
85
85
  @stopped = true
86
- @request_queue.push self if @request_queue
86
+ @request_queue&.push self
87
87
  end
88
88
  end
89
89
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-firestore
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.1
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Google Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-07 00:00:00.000000000 Z
11
+ date: 2021-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-cloud-core
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 1.24.0
75
+ version: 1.25.1
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 1.24.0
82
+ version: 1.25.1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: minitest
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -262,14 +262,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
262
262
  requirements:
263
263
  - - ">="
264
264
  - !ruby/object:Gem::Version
265
- version: '2.4'
265
+ version: '2.5'
266
266
  required_rubygems_version: !ruby/object:Gem::Requirement
267
267
  requirements:
268
268
  - - ">="
269
269
  - !ruby/object:Gem::Version
270
270
  version: '0'
271
271
  requirements: []
272
- rubygems_version: 3.1.4
272
+ rubygems_version: 3.2.13
273
273
  signing_key:
274
274
  specification_version: 4
275
275
  summary: API Client library for Google Cloud Firestore API