activemodel-datastore 0.3.0 → 0.7.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
- SHA1:
3
- metadata.gz: 42e22683055e9669d08d461101ad0df167ed71af
4
- data.tar.gz: a889f3599926be1f5dbd57fc8411446a46703782
2
+ SHA256:
3
+ metadata.gz: 9b42d53d2541bb4b6195b830a9702d7276976ffe8b2a18fccf8591184225dc01
4
+ data.tar.gz: 4d0639726343a339d1192ac802f5321662e72afb2bc66b0f0a0f3b855fc93cc2
5
5
  SHA512:
6
- metadata.gz: 6726447be7d06ca5630cd0b3516329d9280a3b0240e06d8ca5fe413722d4b699124aba7c3f1634b7dde42bf82a9e9d0b17aff708eb0ed9b98f0626d627e6d74a
7
- data.tar.gz: 44d319fa90658e1ef6ab655a5e85c85a1291505d75dca3a91c0a8aff4ef3cd37774a7b0693c0c89fc9e87310b2bbd6ae5c62a54bcea8a02dd897a53819181952
6
+ metadata.gz: 2714fbfe7c92f1351275bd15e464441b25c4a380f086bc03375525a8aa96de11d916739f5de522eaf1546dab18de4546bd6234385bf09ffb32056ae1aca8ec23
7
+ data.tar.gz: 26eaa3c1d30ca938c4ee25b6ae71a66a611fe0ae84a1afa44d93d7620de3826c18364b68c288bdac63833859b2260ae6a030ed3d304d3c0eaae2a3c03fdfd988
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ### 0.7.0 / 2021-11-04
2
+ * adding support for Ruby 3
3
+
4
+ ### 0.6.0 / 2021-09-20
5
+ * defaulting the Google::Cloud.datastore network timeout to 15 sec and providing the env var DATASTORE_NETWORK_TIMEOUT as an override.
6
+
7
+ ### 0.5.0 / 2020-08-17
8
+ * adding support Google::Cloud::Datastore 2.0.0 (rewritten low-level client, with improved performance and stability).
9
+
10
+ ### 0.4.0 / 2019-08-23
11
+ * adding support for Rails 6
12
+
1
13
  ### 0.3.0 / 2018-04-17
2
14
  * adding Travis CI configuration (rud)
3
15
  * no longer override connection related environment variables if already defined(shao1555)
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Active Model Datastore
2
2
  ===================================
3
3
 
4
- Makes the [google-cloud-datastore](https://github.com/GoogleCloudPlatform/google-cloud-ruby/tree/master/google-cloud-datastore) gem compliant with [active_model](https://github.com/rails/rails/tree/master/activemodel) conventions and compatible with your Rails 5 applications.
4
+ Makes the [google-cloud-datastore](https://github.com/GoogleCloudPlatform/google-cloud-ruby/tree/master/google-cloud-datastore) gem compliant with [active_model](https://github.com/rails/rails/tree/master/activemodel) conventions and compatible with your Rails 5+ applications.
5
5
  ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
6
6
 
7
7
  Why would you want to use Google's NoSQL [Cloud Datastore](https://cloud.google.com/datastore)
@@ -255,6 +255,7 @@ users, cursor = User.all(limit: 7)
255
255
  # @option options [String] :order Sort the results by property name.
256
256
  # @option options [String] :desc_order Sort the results by descending property name.
257
257
  # @option options [Array] :select Retrieve only select properties from the matched entities.
258
+ # @option options [Array] :distinct_on Group results by a list of properties.
258
259
  # @option options [Array] :where Adds a property filter of arrays in the format[name, operator, value].
259
260
  ```
260
261
 
@@ -27,7 +27,8 @@ module CloudDatastore
27
27
  end
28
28
 
29
29
  def self.dataset
30
- @dataset ||= Google::Cloud.datastore
30
+ timeout = ENV.fetch('DATASTORE_NETWORK_TIMEOUT', 15).to_i
31
+ @dataset ||= Google::Cloud.datastore(timeout: timeout)
31
32
  end
32
33
 
33
34
  def self.reset_dataset
@@ -180,6 +180,7 @@ module ActiveModel::Datastore
180
180
  unless attributes.is_a?(Hash)
181
181
  raise ArgumentError, "Hash expected, got #{attributes.class.name} (#{attributes.inspect})"
182
182
  end
183
+
183
184
  attributes
184
185
  end
185
186
 
@@ -214,6 +215,7 @@ module ActiveModel::Datastore
214
215
  #
215
216
  def call_reject_if(attributes, options)
216
217
  return false if destroy_flag?(attributes)
218
+
217
219
  attributes = attributes.with_indifferent_access
218
220
  blank_proc = proc { |attrs| attrs.all? { |_key, value| value.blank? } }
219
221
  options[:reject_if] = blank_proc if options[:reject_if] == :all_blank
@@ -245,7 +247,8 @@ module ActiveModel::Datastore
245
247
  class AssociatedValidator < ActiveModel::EachValidator
246
248
  def validate_each(record, attribute, value)
247
249
  return unless Array(value).reject(&:valid?).any?
248
- record.errors.add(attribute, :invalid, options.merge(value: value))
250
+
251
+ record.errors.add(attribute, :invalid, **options.merge(value: value))
249
252
  end
250
253
  end
251
254
  end
@@ -38,6 +38,7 @@ module ActiveModel::Datastore
38
38
  #
39
39
  def format_property_value(attr, type)
40
40
  return unless send(attr.to_sym).present?
41
+
41
42
  case type.to_sym
42
43
  when :integer
43
44
  send("#{attr.to_sym}=", send(attr.to_sym).to_i)
@@ -70,9 +70,11 @@ module ActiveModel::Datastore
70
70
  unless tracked_attributes.present?
71
71
  raise TrackChangesError, 'Object has not been configured for change tracking.'
72
72
  end
73
+
73
74
  changed = marked_for_destruction? ? true : false
74
75
  tracked_attributes.each do |attr|
75
76
  break if changed
77
+
76
78
  changed = send(attr) != send("#{attr}_was") if send("#{attr}_changed?")
77
79
  end
78
80
  self.exclude_from_save = !changed
@@ -81,6 +83,7 @@ module ActiveModel::Datastore
81
83
 
82
84
  def remove_unmodified_children
83
85
  return unless tracked_attributes.present? && nested_attributes?
86
+
84
87
  nested_attributes.each do |attr|
85
88
  with_changes = Array(send(attr.to_sym)).select(&:values_changed?)
86
89
  send("#{attr}=", with_changes)
@@ -1,5 +1,5 @@
1
1
  module ActiveModel
2
2
  module Datastore
3
- VERSION = '0.3.0'
3
+ VERSION = '0.7.0'
4
4
  end
5
5
  end
@@ -154,6 +154,7 @@ module ActiveModel::Datastore
154
154
  entity = CloudDatastore.dataset.entity self.class.name, id
155
155
  if parent.present?
156
156
  raise ArgumentError, 'Must be a Key' unless parent.is_a? Google::Cloud::Datastore::Key
157
+
157
158
  entity.key.parent = parent
158
159
  elsif parent?
159
160
  entity.key.parent = self.class.parent_key(parent_key_id)
@@ -179,6 +180,7 @@ module ActiveModel::Datastore
179
180
  def update(params)
180
181
  assign_attributes(params)
181
182
  return unless valid?
183
+
182
184
  run_callbacks :update do
183
185
  entity = build_entity
184
186
  self.class.retry_on_exception? { CloudDatastore.dataset.save entity }
@@ -197,6 +199,7 @@ module ActiveModel::Datastore
197
199
 
198
200
  def save_entity(parent = nil)
199
201
  return unless valid?
202
+
200
203
  run_callbacks :save do
201
204
  entity = build_entity(parent)
202
205
  success = self.class.retry_on_exception? { CloudDatastore.dataset.save entity }
@@ -273,6 +276,7 @@ module ActiveModel::Datastore
273
276
  # @option options [String] :order Sort the results by property name.
274
277
  # @option options [String] :desc_order Sort the results by descending property name.
275
278
  # @option options [Array] :select Retrieve only select properties from the matched entities.
279
+ # @option options [Array] :distinct_on Group results by a list of properties.
276
280
  # @option options [Array] :where Adds a property filter of arrays in the format
277
281
  # [name, operator, value].
278
282
  #
@@ -352,6 +356,7 @@ module ActiveModel::Datastore
352
356
  #
353
357
  def from_entities(entities)
354
358
  raise ArgumentError, 'Entities param must be an Enumerator' unless entities.is_a? Enumerator
359
+
355
360
  entities.map { |entity| from_entity(entity) }
356
361
  end
357
362
 
@@ -363,6 +368,7 @@ module ActiveModel::Datastore
363
368
  #
364
369
  def from_entity(entity)
365
370
  return if entity.nil?
371
+
366
372
  model_entity = build_model(entity)
367
373
  model_entity.entity_property_values = entity.properties.to_h
368
374
  entity.properties.to_h.each do |name, value|
@@ -383,6 +389,7 @@ module ActiveModel::Datastore
383
389
  # @option options [String] :order Sort the results by property name.
384
390
  # @option options [String] :desc_order Sort the results by descending property name.
385
391
  # @option options [Array] :select Retrieve only select properties from the matched entities.
392
+ # @option options [Array] :distinct_on Group results by a list of properties.
386
393
  # @option options [Array] :where Adds a property filter of arrays in the format
387
394
  # [name, operator, value].
388
395
  #
@@ -400,6 +407,7 @@ module ActiveModel::Datastore
400
407
  yield
401
408
  rescue Google::Cloud::Error => e
402
409
  return false if retries >= max_retry_count
410
+
403
411
  puts "\e[33mRescued exception #{e.message.inspect}, retrying in #{sleep_time}\e[0m"
404
412
  # 0.25, 0.5, 1, 2, and 4 second between retries.
405
413
  sleep sleep_time
@@ -416,6 +424,7 @@ module ActiveModel::Datastore
416
424
  yield
417
425
  rescue Google::Cloud::Error => e
418
426
  raise e if retries >= max_retry_count
427
+
419
428
  puts "\e[33mRescued exception #{e.message.inspect}, retrying in #{sleep_time}\e[0m"
420
429
  # 0.25, 0.5, 1, 2, and 4 second between retries.
421
430
  sleep sleep_time
@@ -440,6 +449,7 @@ module ActiveModel::Datastore
440
449
  query.limit(options[:limit]) if options[:limit]
441
450
  query_sort(query, options)
442
451
  query.select(*options[:select]) if options[:select]
452
+ query.distinct_on(*options[:distinct_on]) if options[:distinct_on]
443
453
  query_property_filter(query, options)
444
454
  end
445
455
 
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activemodel-datastore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryce McLean
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-17 00:00:00.000000000 Z
11
+ date: 2021-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.0'
19
+ version: 5.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '5.0'
26
+ version: 5.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '5.0'
33
+ version: 5.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '5.0'
40
+ version: 5.0.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: google-cloud-datastore
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.0'
47
+ version: '2.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.0'
54
+ version: '2.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -70,50 +70,50 @@ dependencies:
70
70
  name: actionpack
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '5.0'
75
+ version: 5.0.0
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: '5.0'
82
+ version: 5.0.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: factory_bot
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '4.8'
89
+ version: '6.1'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '4.8'
96
+ version: '6.1'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: faker
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '1.7'
103
+ version: '2.1'
104
104
  - - ">="
105
105
  - !ruby/object:Gem::Version
106
- version: 1.7.3
106
+ version: 2.1.2
107
107
  type: :development
108
108
  prerelease: false
109
109
  version_requirements: !ruby/object:Gem::Requirement
110
110
  requirements:
111
111
  - - "~>"
112
112
  - !ruby/object:Gem::Version
113
- version: '1.7'
113
+ version: '2.1'
114
114
  - - ">="
115
115
  - !ruby/object:Gem::Version
116
- version: 1.7.3
116
+ version: 2.1.2
117
117
  - !ruby/object:Gem::Dependency
118
118
  name: minitest
119
119
  requirement: !ruby/object:Gem::Requirement
@@ -134,28 +134,28 @@ dependencies:
134
134
  requirements:
135
135
  - - "~>"
136
136
  - !ruby/object:Gem::Version
137
- version: '0.48'
137
+ version: '1.14'
138
138
  type: :development
139
139
  prerelease: false
140
140
  version_requirements: !ruby/object:Gem::Requirement
141
141
  requirements:
142
142
  - - "~>"
143
143
  - !ruby/object:Gem::Version
144
- version: '0.48'
144
+ version: '1.14'
145
145
  - !ruby/object:Gem::Dependency
146
146
  name: carrierwave
147
147
  requirement: !ruby/object:Gem::Requirement
148
148
  requirements:
149
149
  - - "~>"
150
150
  - !ruby/object:Gem::Version
151
- version: '1.1'
151
+ version: '2.1'
152
152
  type: :development
153
153
  prerelease: false
154
154
  version_requirements: !ruby/object:Gem::Requirement
155
155
  requirements:
156
156
  - - "~>"
157
157
  - !ruby/object:Gem::Version
158
- version: '1.1'
158
+ version: '2.1'
159
159
  description: Makes the google-cloud-datastore gem compliant with active_model conventions
160
160
  and compatible with your Rails 5+ applications.
161
161
  email:
@@ -185,7 +185,7 @@ metadata:
185
185
  changelog_uri: https://github.com/Agrimatics/activemodel-datastore/blob/master/CHANGELOG.md
186
186
  source_code_uri: https://github.com/Agrimatics/activemodel-datastore/
187
187
  bug_tracker_uri: https://github.com/Agrimatics/activemodel-datastore/issues
188
- post_install_message:
188
+ post_install_message:
189
189
  rdoc_options: []
190
190
  require_paths:
191
191
  - lib
@@ -200,9 +200,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
200
  - !ruby/object:Gem::Version
201
201
  version: '0'
202
202
  requirements: []
203
- rubyforge_project:
204
- rubygems_version: 2.6.14
205
- signing_key:
203
+ rubygems_version: 3.2.22
204
+ signing_key:
206
205
  specification_version: 4
207
206
  summary: Cloud Datastore integration with Active Model
208
207
  test_files: []