activemodel-datastore 0.2.5 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 1c51e60669ae324f89ee6d6ceb70aedcc1b8f3e1
4
- data.tar.gz: a71e2146d58414c7c3251cf5452d65fa11f4613d
2
+ SHA256:
3
+ metadata.gz: 6cb0d9446cce815b9dd1b3ef33c955b79c2170643256b60e059b867e7c39fa09
4
+ data.tar.gz: 8b3664f1e5bbe8aad5647397d392f5d80071a943c5dc86bd1a06126aa2ef04ee
5
5
  SHA512:
6
- metadata.gz: 211b19499c3c1523805e4989641d44bb4253afb80fccf0a885e385bfe2ba45abe94cac1a121acb878605da46bc5ac858451642d89d291ee79c85b89269145e4d
7
- data.tar.gz: aee1048afd652a79d7cc45fa94d0a4e438c85b08f6b7bf642b149378be1bea1bed23918ad56f225082c074edb00a01ba4647398c7d4a00487c339ead8208107a
6
+ metadata.gz: daf7db6ad22662105e6fe1e8be137abf3a1e65d3effdc9dad679edfa4d6ae1ab4d523e6958699bbaf795e40ce59c2e7e8a9f8f8c787879915524f06f6ed15822
7
+ data.tar.gz: 8cbfa6c1916501f812be09040bcd34e4d0de7cac93aa24fe52781cd82fcc6924f96495da39f029998a837c3ab78ddec0f085ecda64f96fcd86927a5413df218b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ### 0.6.0 / 2021-09-20
2
+ * defaulting the Google::Cloud.datastore network timeout to 15 sec and providing the env var DATASTORE_NETWORK_TIMEOUT as an override.
3
+
4
+ ### 0.5.0 / 2020-08-17
5
+ * adding support Google::Cloud::Datastore 2.0.0 (rewritten low-level client, with improved performance and stability).
6
+
7
+ ### 0.4.0 / 2019-08-23
8
+ * adding support for Rails 6
9
+
10
+ ### 0.3.0 / 2018-04-17
11
+ * adding Travis CI configuration (rud)
12
+ * no longer override connection related environment variables if already defined(shao1555)
13
+ * adding support for passing query an array of select properties
14
+
1
15
  ### 0.2.5 / 2017-11-06
2
16
  * adding support for setting indexed false on individual entity properties
3
17
  * updating example Cloud Datastore Rails app to 5.1.4
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)
@@ -13,6 +13,7 @@ automatically scales to handle your applications' load. Cloud Datastore is a sch
13
13
  suited for unstructured or semi-structured application data.
14
14
 
15
15
  [![Gem Version](https://badge.fury.io/rb/activemodel-datastore.svg)](https://badge.fury.io/rb/activemodel-datastore)
16
+ [![Build Status](https://travis-ci.org/Agrimatics/activemodel-datastore.svg?branch=master)](https://travis-ci.org/Agrimatics/activemodel-datastore)
16
17
 
17
18
  ## Table of contents
18
19
 
@@ -254,6 +255,7 @@ users, cursor = User.all(limit: 7)
254
255
  # @option options [String] :order Sort the results by property name.
255
256
  # @option options [String] :desc_order Sort the results by descending property name.
256
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.
257
259
  # @option options [Array] :where Adds a property filter of arrays in the format[name, operator, value].
258
260
  ```
259
261
 
@@ -14,20 +14,21 @@
14
14
  module CloudDatastore
15
15
  if defined?(Rails) == 'constant'
16
16
  if Rails.env.development?
17
- ENV['DATASTORE_EMULATOR_HOST'] = 'localhost:8180'
18
- ENV['GCLOUD_PROJECT'] = 'local-datastore'
17
+ ENV['DATASTORE_EMULATOR_HOST'] ||= 'localhost:8180'
18
+ ENV['GCLOUD_PROJECT'] ||= 'local-datastore'
19
19
  elsif Rails.env.test?
20
- ENV['DATASTORE_EMULATOR_HOST'] = 'localhost:8181'
21
- ENV['GCLOUD_PROJECT'] = 'test-datastore'
20
+ ENV['DATASTORE_EMULATOR_HOST'] ||= 'localhost:8181'
21
+ ENV['GCLOUD_PROJECT'] ||= 'test-datastore'
22
22
  elsif ENV['SERVICE_ACCOUNT_PRIVATE_KEY'].present? &&
23
23
  ENV['SERVICE_ACCOUNT_CLIENT_EMAIL'].present?
24
- ENV['GCLOUD_KEYFILE_JSON'] = '{"private_key": "' + ENV['SERVICE_ACCOUNT_PRIVATE_KEY'] + '",
24
+ ENV['GCLOUD_KEYFILE_JSON'] ||= '{"private_key": "' + ENV['SERVICE_ACCOUNT_PRIVATE_KEY'] + '",
25
25
  "client_email": "' + ENV['SERVICE_ACCOUNT_CLIENT_EMAIL'] + '"}'
26
26
  end
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
@@ -105,9 +105,7 @@ module ActiveModel::Datastore
105
105
 
106
106
  def nested_model_class_names
107
107
  entity_kinds = []
108
- if nested_attributes?
109
- nested_models.each { |x| entity_kinds << x.class.name }
110
- end
108
+ nested_models.each { |x| entity_kinds << x.class.name } if nested_attributes?
111
109
  entity_kinds.uniq
112
110
  end
113
111
 
@@ -182,6 +180,7 @@ module ActiveModel::Datastore
182
180
  unless attributes.is_a?(Hash)
183
181
  raise ArgumentError, "Hash expected, got #{attributes.class.name} (#{attributes.inspect})"
184
182
  end
183
+
185
184
  attributes
186
185
  end
187
186
 
@@ -216,6 +215,7 @@ module ActiveModel::Datastore
216
215
  #
217
216
  def call_reject_if(attributes, options)
218
217
  return false if destroy_flag?(attributes)
218
+
219
219
  attributes = attributes.with_indifferent_access
220
220
  blank_proc = proc { |attrs| attrs.all? { |_key, value| value.blank? } }
221
221
  options[:reject_if] = blank_proc if options[:reject_if] == :all_blank
@@ -247,6 +247,7 @@ module ActiveModel::Datastore
247
247
  class AssociatedValidator < ActiveModel::EachValidator
248
248
  def validate_each(record, attribute, value)
249
249
  return unless Array(value).reject(&:valid?).any?
250
+
250
251
  record.errors.add(attribute, :invalid, options.merge(value: value))
251
252
  end
252
253
  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.2.5'
3
+ VERSION = '0.6.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
@@ -439,7 +448,8 @@ module ActiveModel::Datastore
439
448
  query.cursor(options[:cursor]) if options[:cursor]
440
449
  query.limit(options[:limit]) if options[:limit]
441
450
  query_sort(query, options)
442
- query.select(options[:select]) if options[:select]
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.2.5
4
+ version: 0.6.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: 2017-11-06 00:00:00.000000000 Z
11
+ date: 2021-09-20 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
@@ -128,54 +128,34 @@ dependencies:
128
128
  - - "~>"
129
129
  - !ruby/object:Gem::Version
130
130
  version: '5.10'
131
- - !ruby/object:Gem::Dependency
132
- name: minitest-reporters
133
- requirement: !ruby/object:Gem::Requirement
134
- requirements:
135
- - - "~>"
136
- - !ruby/object:Gem::Version
137
- version: '1.1'
138
- - - ">="
139
- - !ruby/object:Gem::Version
140
- version: 1.1.14
141
- type: :development
142
- prerelease: false
143
- version_requirements: !ruby/object:Gem::Requirement
144
- requirements:
145
- - - "~>"
146
- - !ruby/object:Gem::Version
147
- version: '1.1'
148
- - - ">="
149
- - !ruby/object:Gem::Version
150
- version: 1.1.14
151
131
  - !ruby/object:Gem::Dependency
152
132
  name: rubocop
153
133
  requirement: !ruby/object:Gem::Requirement
154
134
  requirements:
155
135
  - - "~>"
156
136
  - !ruby/object:Gem::Version
157
- version: '0.48'
137
+ version: '1.14'
158
138
  type: :development
159
139
  prerelease: false
160
140
  version_requirements: !ruby/object:Gem::Requirement
161
141
  requirements:
162
142
  - - "~>"
163
143
  - !ruby/object:Gem::Version
164
- version: '0.48'
144
+ version: '1.14'
165
145
  - !ruby/object:Gem::Dependency
166
146
  name: carrierwave
167
147
  requirement: !ruby/object:Gem::Requirement
168
148
  requirements:
169
149
  - - "~>"
170
150
  - !ruby/object:Gem::Version
171
- version: '1.1'
151
+ version: '2.1'
172
152
  type: :development
173
153
  prerelease: false
174
154
  version_requirements: !ruby/object:Gem::Requirement
175
155
  requirements:
176
156
  - - "~>"
177
157
  - !ruby/object:Gem::Version
178
- version: '1.1'
158
+ version: '2.1'
179
159
  description: Makes the google-cloud-datastore gem compliant with active_model conventions
180
160
  and compatible with your Rails 5+ applications.
181
161
  email:
@@ -200,8 +180,12 @@ files:
200
180
  homepage: https://github.com/Agrimatics/activemodel-datastore
201
181
  licenses:
202
182
  - MIT
203
- metadata: {}
204
- post_install_message:
183
+ metadata:
184
+ homepage_uri: https://github.com/Agrimatics/activemodel-datastore
185
+ changelog_uri: https://github.com/Agrimatics/activemodel-datastore/blob/master/CHANGELOG.md
186
+ source_code_uri: https://github.com/Agrimatics/activemodel-datastore/
187
+ bug_tracker_uri: https://github.com/Agrimatics/activemodel-datastore/issues
188
+ post_install_message:
205
189
  rdoc_options: []
206
190
  require_paths:
207
191
  - lib
@@ -216,9 +200,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
200
  - !ruby/object:Gem::Version
217
201
  version: '0'
218
202
  requirements: []
219
- rubyforge_project:
220
- rubygems_version: 2.6.13
221
- signing_key:
203
+ rubygems_version: 3.1.6
204
+ signing_key:
222
205
  specification_version: 4
223
206
  summary: Cloud Datastore integration with Active Model
224
207
  test_files: []