primer 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.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ === 0.2.2 / 2011-07-22
2
+
3
+ * Stop using AssociationReflection#class_name to match associations
4
+
5
+
1
6
  === 0.2.1 / 2011-07-20
2
7
 
3
8
  * Fix in a bug in code that loads associated ActiveRecord classes
@@ -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
- mirror = mirror_association(model.class, owner_class, :has_many)
51
-
52
- if owner = model.__send__(assoc_name)
53
- Primer.bus.publish(:changes, owner.primer_identifier + [mirror.name.to_s])
54
- notify_has_many_through_association(owner, mirror.name)
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
- mirror = mirror_association(model.class, object.class, :belongs_to)
76
- next unless mirror
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 mirror_association(object_class, related_class, macro)
104
- long_name = object_class.name
105
- short_name = long_name.split('::').last
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.1
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-20 00:00:00 +01:00
13
+ date: 2011-07-22 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency