activerecord-redundancy 0.2.1 → 0.2.2
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_base.rb +13 -4
- data/lib/redundancy/update_prev_method.rb +0 -1
- data/lib/redundancy/version.rb +1 -1
- data/lib/redundancy.rb +9 -2
- 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: 504c28b1fdbd3e01948e48a5823d95148023ce59
|
4
|
+
data.tar.gz: fbd3a059de3d014b8b20bbc1da47a53e08ecc2e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60c35703583a72dc60dc140ad45ccb346192cdd92116ab9a88e5a09ba6e33275b4cd1dd36fcbe4e4ff349ee00ec8de2e99fd7419b26bd2433b41af88fc63c94f
|
7
|
+
data.tar.gz: ac6f62a775f5db3fe3d19dfdd1658db2e5c188a13522fab4d9670ac933579603638a70019d12fb4a67328b7acb28407266d8c2e291f82a0a7502f55539b54939
|
@@ -3,7 +3,8 @@ module Redundancy
|
|
3
3
|
class UpdateBase
|
4
4
|
attr_reader :options
|
5
5
|
attr_reader :source, :dest, :klass
|
6
|
-
attr_reader :change_if, :update, :
|
6
|
+
attr_reader :change_if, :update, :force
|
7
|
+
attr_reader :target, :value
|
7
8
|
|
8
9
|
def initialize options
|
9
10
|
@options = options
|
@@ -14,6 +15,13 @@ module Redundancy
|
|
14
15
|
@update = options[:update] || false
|
15
16
|
end
|
16
17
|
|
18
|
+
def force_update! record
|
19
|
+
@force = true
|
20
|
+
@update = true
|
21
|
+
before_save record
|
22
|
+
after_save record
|
23
|
+
end
|
24
|
+
|
17
25
|
def before_save record
|
18
26
|
end
|
19
27
|
|
@@ -76,11 +84,12 @@ module Redundancy
|
|
76
84
|
end
|
77
85
|
|
78
86
|
def need_update? record
|
79
|
-
!change_if || record.send(:attribute_changed?, change_if)
|
87
|
+
@force || !change_if || record.send(:attribute_changed?, change_if)
|
80
88
|
end
|
81
89
|
|
82
|
-
|
83
|
-
|
90
|
+
# require 'colorize'
|
91
|
+
def log message
|
92
|
+
# puts " Redundancy ".colorize(:green) + message
|
84
93
|
end
|
85
94
|
|
86
95
|
end
|
data/lib/redundancy/version.rb
CHANGED
data/lib/redundancy.rb
CHANGED
@@ -24,8 +24,7 @@ module Redundancy
|
|
24
24
|
|
25
25
|
def update_redundacies
|
26
26
|
self.class.redundacies.each do |redundancy|
|
27
|
-
redundancy.
|
28
|
-
redundancy.after_save(self)
|
27
|
+
redundancy.force_update!(self)
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
@@ -44,6 +43,14 @@ module Redundancy
|
|
44
43
|
@redundacies ||= []
|
45
44
|
end
|
46
45
|
|
46
|
+
def update_redundacies
|
47
|
+
all.each do |record|
|
48
|
+
redundacies.each do |redundancy|
|
49
|
+
redundancy.force_update!(record)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
47
54
|
end
|
48
55
|
|
49
56
|
end
|