primer 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/lib/primer/worker/active_record_agent.rb +23 -25
- data/spec/db/test.sqlite3 +0 -0
- metadata +2 -2
data/History.txt
CHANGED
@@ -45,22 +45,24 @@ module Primer
|
|
45
45
|
|
46
46
|
def notify_belongs_to_association(model, assoc_name, change = nil)
|
47
47
|
assoc = model.class.reflect_on_association(assoc_name)
|
48
|
-
owner_class = assoc.klass
|
49
48
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
49
|
+
mirror_associations(model, assoc, :has_many) do |mirror|
|
50
|
+
if owner = model.__send__(assoc_name)
|
51
|
+
Primer.bus.publish(:changes, owner.primer_identifier + [mirror.name.to_s])
|
52
|
+
notify_has_many_through_association(owner, mirror.name)
|
53
|
+
end
|
54
|
+
|
55
|
+
return unless Array === change and change.first.any?
|
56
|
+
|
57
|
+
owner_class = assoc.klass
|
58
|
+
old_id = change.first.first
|
59
|
+
previous = owner_class.find(:first, :conditions => {owner_class.primary_key => old_id})
|
60
|
+
|
61
|
+
return unless previous
|
62
|
+
|
63
|
+
Primer.bus.publish(:changes, previous.primer_identifier + [mirror.name.to_s])
|
64
|
+
notify_has_many_through_association(previous, mirror.name)
|
55
65
|
end
|
56
|
-
|
57
|
-
return unless Array === change and change.first.any?
|
58
|
-
old_id = change.first.first
|
59
|
-
previous = owner_class.find(:first, :conditions => {owner_class.primary_key => old_id})
|
60
|
-
return unless previous
|
61
|
-
|
62
|
-
Primer.bus.publish(:changes, previous.primer_identifier + [mirror.name.to_s])
|
63
|
-
notify_has_many_through_association(previous, mirror.name)
|
64
66
|
end
|
65
67
|
|
66
68
|
def notify_has_many_associations(model)
|
@@ -72,10 +74,9 @@ module Primer
|
|
72
74
|
related = assoc.klass.find(:all, :conditions => {assoc.primary_key_name => model_id})
|
73
75
|
|
74
76
|
related.each do |object|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
Primer.bus.publish(:changes, object.primer_identifier + [mirror.name.to_s])
|
77
|
+
mirror_associations(model, assoc, :belongs_to) do |mirror|
|
78
|
+
Primer.bus.publish(:changes, object.primer_identifier + [mirror.name.to_s])
|
79
|
+
end
|
79
80
|
end
|
80
81
|
end
|
81
82
|
end
|
@@ -100,13 +101,10 @@ module Primer
|
|
100
101
|
end
|
101
102
|
end
|
102
103
|
|
103
|
-
def
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
related_class.reflect_on_all_associations.find do |mirror_assoc|
|
108
|
-
mirror_assoc.macro == macro and
|
109
|
-
[long_name, short_name].include?(mirror_assoc.class_name)
|
104
|
+
def mirror_associations(model, association, macro)
|
105
|
+
association.klass.reflect_on_all_associations.each do |mirror|
|
106
|
+
yield(mirror) if mirror.klass == model.class and
|
107
|
+
mirror.macro == macro
|
110
108
|
end
|
111
109
|
end
|
112
110
|
end
|
data/spec/db/test.sqlite3
CHANGED
Binary file
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: primer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.2.
|
5
|
+
version: 0.2.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James Coglan
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-07-
|
13
|
+
date: 2011-07-22 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|