adequate_serialization 2.0.0 → 2.0.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 273a3e30de9eed1f993b3f83aae405a660bc84aea6f9bf59682c7d99ca838a9c
|
4
|
+
data.tar.gz: e3ec7712f4f66088ec4017b4add90977c3282b0d057362bc14d4bf2ed30c1c49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebf077cfd6ddfbd155a45fcdbff67ab31f003adc2df6567e1d672cee581b6fbd58e021ceb7a011fd98e54cdecf4a3f9cfbab346b3c6e996defbb34669bdd1050
|
7
|
+
data.tar.gz: 5a2641ee46b36951066f77670b15fe80fe8b48bbaa41808a3d359a2c8fcf89766b7e638b435dffceaf1dc90e905bd1ffc73ca0559100781763d1e5bea433165a
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,18 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [2.0.1] - 2020-01-02
|
10
|
+
|
11
|
+
### Added
|
12
|
+
|
13
|
+
- The top level `AdequateSerialization::associate_cache` method for arbitrarily associating caches between records. Useful for things like polymorphic associations which cannot be performed automatically.
|
14
|
+
|
15
|
+
### Changed
|
16
|
+
|
17
|
+
- Fixed the active job queue setting configuration so that it will properly update ActiveJob when using Sidekiq.
|
18
|
+
- Fixed the cache busting for regular has_many relationships.
|
19
|
+
- Changed the name of the `::serialized_associations` method to `::associated_caches` to be more clear.
|
20
|
+
|
9
21
|
## [2.0.0] - 2019-12-31
|
10
22
|
|
11
23
|
### Added
|
@@ -46,7 +58,9 @@ end
|
|
46
58
|
|
47
59
|
- No longer trigger another query when the `ActiveRecord` relation being serialized isn't loaded.
|
48
60
|
|
49
|
-
[unreleased]: https://github.com/CultureHQ/adequate_serialization/compare/
|
61
|
+
[unreleased]: https://github.com/CultureHQ/adequate_serialization/compare/v2.0.1...HEAD
|
62
|
+
[2.0.1]: https://github.com/CultureHQ/adequate_serialization/compare/v2.0.0...v2.0.1
|
63
|
+
[2.0.0]: https://github.com/CultureHQ/adequate_serialization/compare/v1.0.1...v2.0.0
|
50
64
|
[1.0.1]: https://github.com/CultureHQ/adequate_serialization/compare/v1.0.0...v1.0.1
|
51
65
|
[1.0.0]: https://github.com/CultureHQ/adequate_serialization/compare/v0.1.1...v1.0.0
|
52
66
|
[0.1.1]: https://github.com/CultureHQ/adequate_serialization/compare/fcc7c7...v0.1.1
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
adequate_serialization (2.0.
|
4
|
+
adequate_serialization (2.0.1)
|
5
5
|
oj (~> 3.10)
|
6
6
|
|
7
7
|
GEM
|
@@ -76,7 +76,7 @@ GEM
|
|
76
76
|
i18n (1.7.0)
|
77
77
|
concurrent-ruby (~> 1.0)
|
78
78
|
jaro_winkler (1.5.4)
|
79
|
-
json (2.
|
79
|
+
json (2.3.0)
|
80
80
|
loofah (2.4.0)
|
81
81
|
crass (~> 1.0.2)
|
82
82
|
nokogiri (>= 1.5.9)
|
@@ -94,7 +94,7 @@ GEM
|
|
94
94
|
mini_portile2 (~> 2.4.0)
|
95
95
|
oj (3.10.0)
|
96
96
|
parallel (1.19.1)
|
97
|
-
parser (2.
|
97
|
+
parser (2.7.0.1)
|
98
98
|
ast (~> 2.4.0)
|
99
99
|
rack (2.0.8)
|
100
100
|
rack-test (1.1.0)
|
@@ -150,7 +150,7 @@ GEM
|
|
150
150
|
sqlite3 (1.4.2)
|
151
151
|
thor (0.20.3)
|
152
152
|
thread_safe (0.3.6)
|
153
|
-
tzinfo (1.2.
|
153
|
+
tzinfo (1.2.6)
|
154
154
|
thread_safe (~> 0.1)
|
155
155
|
unicode-display_width (1.6.0)
|
156
156
|
websocket-driver (0.7.1)
|
@@ -10,14 +10,36 @@ module AdequateSerialization
|
|
10
10
|
end
|
11
11
|
|
12
12
|
class << self
|
13
|
-
|
13
|
+
attr_reader :active_job_queue
|
14
14
|
|
15
|
+
# Configure the queue name that AdequateSerialization will use when
|
16
|
+
# enqueuing jobs to bust associated caches.
|
17
|
+
def active_job_queue=(queue_name)
|
18
|
+
require 'adequate_serialization/rails/cache_refresh'
|
19
|
+
CacheRefresh::CacheRefreshJob.queue_name = queue_name
|
20
|
+
end
|
21
|
+
|
22
|
+
# Associate one or more caches with an active record such that when the
|
23
|
+
# record is updated the associated object caches are also updated.
|
24
|
+
def associate_cache(active_record, *association_names)
|
25
|
+
require 'adequate_serialization/rails/cache_refresh'
|
26
|
+
|
27
|
+
unless active_record.respond_to?(:associate_cache)
|
28
|
+
active_record.extend(CacheRefresh)
|
29
|
+
end
|
30
|
+
|
31
|
+
association_names.each do |association_name|
|
32
|
+
active_record.associate_cache(association_name)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# DSL-like block for parity with other Ruby/Rails libraries.
|
15
37
|
def configure
|
16
38
|
yield self
|
17
39
|
end
|
18
40
|
end
|
19
41
|
|
20
|
-
|
42
|
+
@active_job_queue = :default
|
21
43
|
end
|
22
44
|
|
23
45
|
require 'adequate_serialization/attribute'
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module AdequateSerialization
|
4
4
|
module CacheBusting
|
5
|
-
class InverseNotFoundError <
|
5
|
+
class InverseNotFoundError < Error
|
6
6
|
def initialize(record, association)
|
7
7
|
super(<<~MSG)
|
8
8
|
In order to be able to bust the associated cache for #{record}'s
|
@@ -14,7 +14,7 @@ module AdequateSerialization
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
class TouchNotFoundError <
|
17
|
+
class TouchNotFoundError < Error
|
18
18
|
def initialize(record, associated, inverse)
|
19
19
|
super(<<~MSG)
|
20
20
|
#{record} serializes all of the associated #{associated} records,
|
@@ -40,15 +40,12 @@ module AdequateSerialization
|
|
40
40
|
using(
|
41
41
|
Module.new do
|
42
42
|
refine ActiveRecord::Base.singleton_class do
|
43
|
-
def
|
43
|
+
def setup_association_cache(association_name)
|
44
44
|
unless defined?(ActiveJob)
|
45
45
|
raise ActiveJobNotFoundError.new(name, association_name)
|
46
46
|
end
|
47
47
|
|
48
|
-
|
49
|
-
extend(CacheRefresh) unless respond_to?(:serialize_association)
|
50
|
-
|
51
|
-
serialize_association(association_name)
|
48
|
+
AdequateSerialization.associate_cache(self, association_name)
|
52
49
|
end
|
53
50
|
end
|
54
51
|
|
@@ -80,7 +77,7 @@ module AdequateSerialization
|
|
80
77
|
# Hooks into the serialized class and adds cache busting behavior on
|
81
78
|
# commit that will loop through the associated records
|
82
79
|
def setup_has_some
|
83
|
-
|
80
|
+
klass.setup_association_cache(inverse_of.name)
|
84
81
|
end
|
85
82
|
end
|
86
83
|
|
@@ -90,7 +87,7 @@ module AdequateSerialization
|
|
90
87
|
raise InverseNotFoundError.new(active_record.name, name)
|
91
88
|
end
|
92
89
|
|
93
|
-
klass.
|
90
|
+
klass.setup_association_cache(inverse_of.name)
|
94
91
|
end
|
95
92
|
end
|
96
93
|
end
|
@@ -33,11 +33,11 @@ module AdequateSerialization
|
|
33
33
|
end
|
34
34
|
)
|
35
35
|
|
36
|
-
queue_as
|
36
|
+
queue_as AdequateSerialization.active_job_queue
|
37
37
|
discard_on ActiveJob::DeserializationError
|
38
38
|
|
39
39
|
def perform(record)
|
40
|
-
record.class.
|
40
|
+
record.class.associated_caches.each do |association|
|
41
41
|
record.public_send(association).refresh
|
42
42
|
end
|
43
43
|
end
|
@@ -47,14 +47,14 @@ module AdequateSerialization
|
|
47
47
|
base.after_update_commit { CacheRefreshJob.perform_later(self) }
|
48
48
|
end
|
49
49
|
|
50
|
-
def
|
51
|
-
|
50
|
+
def associate_cache(association)
|
51
|
+
associated_caches << association
|
52
52
|
end
|
53
53
|
|
54
54
|
# The associations that serialize this object in their responses, so that we
|
55
55
|
# know to bust their cache when this object is updated.
|
56
|
-
def
|
57
|
-
@
|
56
|
+
def associated_caches
|
57
|
+
@associated_caches ||= []
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adequate_serialization
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Deisz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|