activerecord-redundancy 0.2.2 → 0.3.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 +4 -4
- data/lib/redundancy/update_prev_method.rb +1 -1
- data/lib/redundancy/utils.rb +10 -8
- data/lib/redundancy/version.rb +1 -1
- data/test/support/models/post.rb +0 -3
- data/test/support/models/user.rb +3 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbed46abce552a4b6c0bb975fbdeb45acd10c638
|
4
|
+
data.tar.gz: ec046b565f92b938eb81e5b62c710a2878be44fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c5dee5844b4784e2608e2fc1cbb07c1e87a0e3024db1f04a48e4d88d55ac0117809768824068930a74ca0dce57ef7d3abe042e276dda735c3a332dca2d49cb9
|
7
|
+
data.tar.gz: c3983f7a81384676b34a5bc01684f96fc8fb476a272ca06ca611a168496c346564093e16302812237739fcaaea4f48f6f7b9ec56d1616a69b204e55755c77fd5
|
data/lib/redundancy/utils.rb
CHANGED
@@ -55,24 +55,26 @@ module Redundancy
|
|
55
55
|
local_klass = klass
|
56
56
|
|
57
57
|
reflection = get_reflection local_klass, association
|
58
|
-
raise ArgumentError, "
|
59
|
-
[:
|
58
|
+
raise ArgumentError, "HasOne or HasMany reflection required" unless
|
59
|
+
[:has_one, :has_many].include? reflection.macro
|
60
60
|
|
61
61
|
foreign_key = reflection.foreign_key
|
62
62
|
remote_klass = reflection.klass
|
63
63
|
|
64
|
+
inverse_association = get_inverse_association local_klass, remote_klass, options
|
65
|
+
|
64
66
|
cache_method = options[:cache_method] || :"raw_#{attribute}"
|
65
67
|
|
66
|
-
|
68
|
+
remote_klass.redundacies << UpdateMethod.new(
|
67
69
|
source: { attribute: cache_method },
|
68
|
-
dest: { association:
|
69
|
-
change_if: options[:change_if], klass:
|
70
|
+
dest: { association: inverse_association, attribute: attribute },
|
71
|
+
change_if: options[:change_if], klass: remote_klass
|
70
72
|
)
|
71
73
|
|
72
|
-
|
74
|
+
remote_klass.redundacies << UpdatePrevMethod.new(
|
73
75
|
source: { attribute: cache_method },
|
74
|
-
dest: { klass:
|
75
|
-
change_if: foreign_key, klass:
|
76
|
+
dest: { klass: local_klass, prev_id: foreign_key, attribute: attribute },
|
77
|
+
change_if: foreign_key, klass: remote_klass
|
76
78
|
)
|
77
79
|
|
78
80
|
end
|
data/lib/redundancy/version.rb
CHANGED
data/test/support/models/post.rb
CHANGED
data/test/support/models/user.rb
CHANGED