activerecord-redundancy 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/redundancy.rb +12 -12
- data/lib/redundancy/utils.rb +6 -6
- data/lib/redundancy/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e68d174487cbdb7ec2061bf60b3a39058f645fa
|
4
|
+
data.tar.gz: c6a6434b61bc4cd1275a1cf4529b36e19b35640b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9875b90b5647087742c36a47d6e2ed9d179afa5f428352dda99a655179d4b882e44fed248d5629941828c7a7268f01185c7ee9a4d2acaac69b0e469b9788c619
|
7
|
+
data.tar.gz: 918fee0e77240ed84720392af096f75d8138071606e28dd3ff49efa66466a7b796622d48f9b4bd87aac26c1dec21a8cb1e203bd97735fdb58f4e08b63a7c9469
|
data/lib/redundancy.rb
CHANGED
@@ -4,26 +4,26 @@ module Redundancy
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
7
|
-
before_save :
|
8
|
-
after_save :
|
7
|
+
before_save :update_redundancies_before_save
|
8
|
+
after_save :update_redundancies_after_save
|
9
9
|
end
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
|
-
def
|
14
|
-
self.class.
|
13
|
+
def update_redundancies_before_save
|
14
|
+
self.class.redundancies.each do |redundancy|
|
15
15
|
redundancy.before_save(self)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
self.class.
|
19
|
+
def update_redundancies_after_save
|
20
|
+
self.class.redundancies.each do |redundancy|
|
21
21
|
redundancy.after_save(self)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
26
|
-
self.class.
|
25
|
+
def update_redundancies
|
26
|
+
self.class.redundancies.each do |redundancy|
|
27
27
|
redundancy.force_update!(self)
|
28
28
|
end
|
29
29
|
end
|
@@ -39,13 +39,13 @@ module Redundancy
|
|
39
39
|
Utils.cache_method self, association, attribute, options
|
40
40
|
end
|
41
41
|
|
42
|
-
def
|
43
|
-
@
|
42
|
+
def redundancies
|
43
|
+
@redundancies ||= []
|
44
44
|
end
|
45
45
|
|
46
|
-
def
|
46
|
+
def update_redundancies
|
47
47
|
all.each do |record|
|
48
|
-
|
48
|
+
redundancies.each do |redundancy|
|
49
49
|
redundancy.force_update!(record)
|
50
50
|
end
|
51
51
|
end
|
data/lib/redundancy/utils.rb
CHANGED
@@ -23,20 +23,20 @@ module Redundancy
|
|
23
23
|
|
24
24
|
case reflection.macro
|
25
25
|
when :belongs_to
|
26
|
-
local_klass.
|
26
|
+
local_klass.redundancies << UpdateColumn.new(
|
27
27
|
source: { association: association, attribute: attribute },
|
28
28
|
dest: { association: nil, attribute: cache_column },
|
29
29
|
change_if: foreign_key, klass: local_klass
|
30
30
|
)
|
31
31
|
|
32
32
|
when :has_one
|
33
|
-
remote_klass.
|
33
|
+
remote_klass.redundancies << UpdateColumn.new(
|
34
34
|
source: { association: nil, attribute: attribute, nil_unless: foreign_key },
|
35
35
|
dest: { association: inverse_association, attribute: cache_column },
|
36
36
|
change_if: foreign_key, klass: remote_klass
|
37
37
|
)
|
38
38
|
|
39
|
-
remote_klass.
|
39
|
+
remote_klass.redundancies << UpdatePrevColumn.new(
|
40
40
|
source: options[:default],
|
41
41
|
dest: { klass: local_klass, prev_id: foreign_key, attribute: cache_column },
|
42
42
|
change_if: foreign_key, klass: remote_klass
|
@@ -44,7 +44,7 @@ module Redundancy
|
|
44
44
|
|
45
45
|
end
|
46
46
|
|
47
|
-
remote_klass.
|
47
|
+
remote_klass.redundancies << UpdateColumn.new(
|
48
48
|
source: { association: nil, attribute: attribute },
|
49
49
|
dest: { association: inverse_association, attribute: cache_column },
|
50
50
|
change_if: attribute, klass: remote_klass, update: true
|
@@ -63,13 +63,13 @@ module Redundancy
|
|
63
63
|
|
64
64
|
cache_method = options[:cache_method] || :"raw_#{attribute}"
|
65
65
|
|
66
|
-
local_klass.
|
66
|
+
local_klass.redundancies << UpdateMethod.new(
|
67
67
|
source: { attribute: cache_method },
|
68
68
|
dest: { association: association, attribute: attribute },
|
69
69
|
change_if: options[:change_if], klass: local_klass
|
70
70
|
)
|
71
71
|
|
72
|
-
local_klass.
|
72
|
+
local_klass.redundancies << UpdatePrevMethod.new(
|
73
73
|
source: { attribute: cache_method },
|
74
74
|
dest: { klass: remote_klass, prev_id: foreign_key, attribute: attribute },
|
75
75
|
change_if: foreign_key, klass: local_klass
|
data/lib/redundancy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-redundancy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Theo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|