activemodel-datastore 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/active_model/datastore.rb +5 -9
- data/lib/active_model/datastore/excluded_indexes.rb +38 -0
- data/lib/active_model/datastore/nested_attr.rb +1 -1
- data/lib/active_model/datastore/track_changes.rb +1 -3
- data/lib/active_model/datastore/version.rb +1 -1
- data/lib/activemodel/datastore.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c51e60669ae324f89ee6d6ceb70aedcc1b8f3e1
|
4
|
+
data.tar.gz: a71e2146d58414c7c3251cf5452d65fa11f4613d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 211b19499c3c1523805e4989641d44bb4253afb80fccf0a885e385bfe2ba45abe94cac1a121acb878605da46bc5ac858451642d89d291ee79c85b89269145e4d
|
7
|
+
data.tar.gz: aee1048afd652a79d7cc45fa94d0a4e438c85b08f6b7bf642b149378be1bea1bed23918ad56f225082c074edb00a01ba4647398c7d4a00487c339ead8208107a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
### 0.2.5 / 2017-11-06
|
2
|
+
* adding support for setting indexed false on individual entity properties
|
3
|
+
* updating example Cloud Datastore Rails app to 5.1.4
|
4
|
+
* retry on exceptions are now specific to Google::Cloud::Error
|
5
|
+
|
1
6
|
### 0.2.4 / 2017-10-31
|
2
7
|
* non-Rails projects now source client authentication settings automatically (rjmooney)
|
3
8
|
* documentation improvements
|
@@ -114,6 +114,7 @@ module ActiveModel::Datastore
|
|
114
114
|
include ActiveModel::Dirty
|
115
115
|
include ActiveModel::Validations
|
116
116
|
include ActiveModel::Validations::Callbacks
|
117
|
+
include ActiveModel::Datastore::ExcludedIndexes
|
117
118
|
include ActiveModel::Datastore::NestedAttr
|
118
119
|
include ActiveModel::Datastore::PropertyValues
|
119
120
|
include ActiveModel::Datastore::TrackChanges
|
@@ -159,6 +160,7 @@ module ActiveModel::Datastore
|
|
159
160
|
end
|
160
161
|
entity_properties.each do |attr|
|
161
162
|
entity[attr] = instance_variable_get("@#{attr}")
|
163
|
+
entity.exclude_from_indexes!(attr, true) if no_index_attributes.include? attr
|
162
164
|
end
|
163
165
|
entity
|
164
166
|
end
|
@@ -168,7 +170,7 @@ module ActiveModel::Datastore
|
|
168
170
|
end
|
169
171
|
|
170
172
|
##
|
171
|
-
# For compatibility with libraries that require the bang method version (example,
|
173
|
+
# For compatibility with libraries that require the bang method version (example, factory_bot).
|
172
174
|
#
|
173
175
|
def save!
|
174
176
|
save_entity || raise(EntityNotSavedError, 'Failed to save the entity')
|
@@ -370,12 +372,6 @@ module ActiveModel::Datastore
|
|
370
372
|
model_entity
|
371
373
|
end
|
372
374
|
|
373
|
-
def exclude_from_index(entity, boolean)
|
374
|
-
entity.properties.to_h.keys.each do |value|
|
375
|
-
entity.exclude_from_indexes! value, boolean
|
376
|
-
end
|
377
|
-
end
|
378
|
-
|
379
375
|
##
|
380
376
|
# Constructs a Google::Cloud::Datastore::Query.
|
381
377
|
#
|
@@ -402,7 +398,7 @@ module ActiveModel::Datastore
|
|
402
398
|
sleep_time = 0.25
|
403
399
|
begin
|
404
400
|
yield
|
405
|
-
rescue => e
|
401
|
+
rescue Google::Cloud::Error => e
|
406
402
|
return false if retries >= max_retry_count
|
407
403
|
puts "\e[33mRescued exception #{e.message.inspect}, retrying in #{sleep_time}\e[0m"
|
408
404
|
# 0.25, 0.5, 1, 2, and 4 second between retries.
|
@@ -418,7 +414,7 @@ module ActiveModel::Datastore
|
|
418
414
|
sleep_time = 0.25
|
419
415
|
begin
|
420
416
|
yield
|
421
|
-
rescue => e
|
417
|
+
rescue Google::Cloud::Error => e
|
422
418
|
raise e if retries >= max_retry_count
|
423
419
|
puts "\e[33mRescued exception #{e.message.inspect}, retrying in #{sleep_time}\e[0m"
|
424
420
|
# 0.25, 0.5, 1, 2, and 4 second between retries.
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module ActiveModel::Datastore
|
2
|
+
module ExcludedIndexes
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
def no_index_attributes
|
6
|
+
[]
|
7
|
+
end
|
8
|
+
|
9
|
+
##
|
10
|
+
# Sets all entity properties to be included/excluded from the Datastore indexes.
|
11
|
+
#
|
12
|
+
def exclude_from_index(entity, boolean)
|
13
|
+
entity.properties.to_h.each_key do |value|
|
14
|
+
entity.exclude_from_indexes! value, boolean
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module ClassMethods
|
19
|
+
##
|
20
|
+
# Sets attributes to be excluded from the Datastore indexes.
|
21
|
+
#
|
22
|
+
# Overrides no_index_attributes to return an Array of the attributes configured
|
23
|
+
# to be indexed.
|
24
|
+
#
|
25
|
+
# For example, an indexed string property can not exceed 1500 bytes. String properties
|
26
|
+
# that are not indexed can be up to 1,048,487 bytes. All properties indexed by default.
|
27
|
+
#
|
28
|
+
def no_indexes(*attributes)
|
29
|
+
attributes = attributes.collect(&:to_s)
|
30
|
+
define_method('no_index_attributes') { attributes }
|
31
|
+
end
|
32
|
+
|
33
|
+
def clear_index_exclusions!
|
34
|
+
define_method('no_index_attributes') { [] }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -159,7 +159,7 @@ module ActiveModel::Datastore
|
|
159
159
|
association_name = association_name.to_sym
|
160
160
|
send("#{association_name}=", []) if send(association_name).nil?
|
161
161
|
|
162
|
-
attributes.
|
162
|
+
attributes.each_value do |params|
|
163
163
|
if params['id'].blank?
|
164
164
|
unless reject_new_record?(params, options)
|
165
165
|
new = association_name.to_c.new(params.except(*UNASSIGNABLE_KEYS))
|
@@ -73,9 +73,7 @@ module ActiveModel::Datastore
|
|
73
73
|
changed = marked_for_destruction? ? true : false
|
74
74
|
tracked_attributes.each do |attr|
|
75
75
|
break if changed
|
76
|
-
if send("#{attr}_changed?")
|
77
|
-
changed = send(attr) == send("#{attr}_was") ? false : true
|
78
|
-
end
|
76
|
+
changed = send(attr) != send("#{attr}_was") if send("#{attr}_changed?")
|
79
77
|
end
|
80
78
|
self.exclude_from_save = !changed
|
81
79
|
changed
|
@@ -7,6 +7,7 @@ require 'active_model'
|
|
7
7
|
|
8
8
|
require 'active_model/datastore/connection'
|
9
9
|
require 'active_model/datastore/errors'
|
10
|
+
require 'active_model/datastore/excluded_indexes'
|
10
11
|
require 'active_model/datastore/nested_attr'
|
11
12
|
require 'active_model/datastore/property_values'
|
12
13
|
require 'active_model/datastore/track_changes'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activemodel-datastore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryce McLean
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '5.0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: factory_bot
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
@@ -191,6 +191,7 @@ files:
|
|
191
191
|
- lib/active_model/datastore/carrier_wave_uploader.rb
|
192
192
|
- lib/active_model/datastore/connection.rb
|
193
193
|
- lib/active_model/datastore/errors.rb
|
194
|
+
- lib/active_model/datastore/excluded_indexes.rb
|
194
195
|
- lib/active_model/datastore/nested_attr.rb
|
195
196
|
- lib/active_model/datastore/property_values.rb
|
196
197
|
- lib/active_model/datastore/track_changes.rb
|