activemodel-datastore 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +3 -0
- data/README.md +1 -0
- data/lib/active_model/datastore.rb +10 -0
- data/lib/active_model/datastore/nested_attr.rb +3 -0
- data/lib/active_model/datastore/property_values.rb +1 -0
- data/lib/active_model/datastore/track_changes.rb +3 -0
- data/lib/active_model/datastore/version.rb +1 -1
- metadata +27 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3294504a43271540afd7aedae54498991121522cdd3a66ac63171d471486dab9
|
4
|
+
data.tar.gz: 95884028548c78db37875c252561b163dfbd9dbde58726cb1b8bda641335e97a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '03672266608c4a3e0ee0a0ee3e9990cfe9ddf9aa40bd296dbe308911e83e1e35ec87454631b61d779722876371082f8875ebc3c518290d76716fdcc30e17224c'
|
7
|
+
data.tar.gz: ba8103e6fc4c8b830a5d3011a87ea2367e57b32fcde9a9203d263afe9d19ee782b5465ef3df999cae2b90cdde0cde74b0659d563d4684fd32f8fa608175dd765
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -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
|
|
@@ -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
|
|
@@ -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,6 +247,7 @@ 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?
|
250
|
+
|
248
251
|
record.errors.add(attribute, :invalid, options.merge(value: value))
|
249
252
|
end
|
250
253
|
end
|
@@ -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)
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activemodel-datastore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryce McLean
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-08-23 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:
|
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:
|
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:
|
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:
|
40
|
+
version: 5.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: google-cloud-datastore
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,50 +70,56 @@ 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:
|
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:
|
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: '
|
89
|
+
version: '5.0'
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 5.0.2
|
90
93
|
type: :development
|
91
94
|
prerelease: false
|
92
95
|
version_requirements: !ruby/object:Gem::Requirement
|
93
96
|
requirements:
|
94
97
|
- - "~>"
|
95
98
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
99
|
+
version: '5.0'
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 5.0.2
|
97
103
|
- !ruby/object:Gem::Dependency
|
98
104
|
name: faker
|
99
105
|
requirement: !ruby/object:Gem::Requirement
|
100
106
|
requirements:
|
101
107
|
- - "~>"
|
102
108
|
- !ruby/object:Gem::Version
|
103
|
-
version: '1
|
109
|
+
version: '2.1'
|
104
110
|
- - ">="
|
105
111
|
- !ruby/object:Gem::Version
|
106
|
-
version: 1.
|
112
|
+
version: 2.1.2
|
107
113
|
type: :development
|
108
114
|
prerelease: false
|
109
115
|
version_requirements: !ruby/object:Gem::Requirement
|
110
116
|
requirements:
|
111
117
|
- - "~>"
|
112
118
|
- !ruby/object:Gem::Version
|
113
|
-
version: '1
|
119
|
+
version: '2.1'
|
114
120
|
- - ">="
|
115
121
|
- !ruby/object:Gem::Version
|
116
|
-
version: 1.
|
122
|
+
version: 2.1.2
|
117
123
|
- !ruby/object:Gem::Dependency
|
118
124
|
name: minitest
|
119
125
|
requirement: !ruby/object:Gem::Requirement
|
@@ -200,8 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
200
206
|
- !ruby/object:Gem::Version
|
201
207
|
version: '0'
|
202
208
|
requirements: []
|
203
|
-
|
204
|
-
rubygems_version: 2.6.14
|
209
|
+
rubygems_version: 3.0.3
|
205
210
|
signing_key:
|
206
211
|
specification_version: 4
|
207
212
|
summary: Cloud Datastore integration with Active Model
|