central_notifications 1.0.1 → 1.0.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/README.rdoc CHANGED
@@ -133,4 +133,8 @@ For that, just register on setter :
133
133
  user = User.new
134
134
  order = Order.new
135
135
  order.amount = 100
136
- #=> From user : The amount has changed and is now: 100
136
+ #=> From user : The amount has changed and is now: 100
137
+
138
+ == ChangeLog
139
+
140
+ FIX : Failures with Ruby 1.9 . #instance_methods, #singleton_methods ... family methods return symbols. Ruby 1.8.x return strings.
data/lib/notifier.rb CHANGED
@@ -22,10 +22,11 @@ module CentralNotifications
22
22
  registration.fork
23
23
  end
24
24
 
25
- def alert(registration)
25
+ def alert(registration, notifier)
26
26
  registrations[registration].each do |notified|
27
27
  ObjectSpace.each_object(notified[:klass]) do |object|
28
28
  object.send(:instance_variable_set, :@registration_result, registration.result)
29
+ object.send(:instance_variable_set, :@notifier_object, notifier)
29
30
  object.send(notified[:method])
30
31
  end
31
32
  end
data/lib/registration.rb CHANGED
@@ -40,7 +40,7 @@ module CentralNotifications
40
40
  @real_klass.send(:define_method, method) do |*params|
41
41
  registration.result = send(original, *params)
42
42
  notifier = (eigenclass ? self : self.class).send(:class_variable_get, NOTIFIER_CLASS_VARIABLE)
43
- notifier.alert(registration)
43
+ notifier.alert(registration, self)
44
44
  registration.result
45
45
  end
46
46
  end
@@ -62,5 +62,13 @@ class TestNotifier < Test::Unit::TestCase
62
62
 
63
63
  order.payment(100)
64
64
  end
65
+
66
+ def test_notified_method_should_be_able_to_know_object_which_triggered_notifications
67
+ user, order = User.new, Order.new
68
+
69
+ result = order.payment(100, :usd)
70
+
71
+ assert_equal order, user.instance_variable_get(:@notifier_object)
72
+ end
65
73
 
66
74
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: central_notifications
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 1
10
- version: 1.0.1
9
+ - 2
10
+ version: 1.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Philippe Cantin
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-20 00:00:00 +01:00
18
+ date: 2010-12-21 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies: []
21
21