activesupport_notifications_backport 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  ## If your rubyforge_project name is different, then edit it and comment out
13
13
  ## the sub! line in the Rakefile
14
14
  s.name = 'activesupport_notifications_backport'
15
- s.version = '0.0.3'
15
+ s.version = '0.0.4'
16
16
  s.date = '2012-03-20'
17
17
  s.rubyforge_project = 'activesupport_notifications_backport'
18
18
 
@@ -109,30 +109,34 @@ module ActiveSupport
109
109
  autoload :Event, File.expand_path('../notifications/instrumenter', __FILE__)
110
110
  autoload :Fanout, File.expand_path('../notifications/fanout', __FILE__)
111
111
 
112
- @instrumenters = Hash.new { |h,k| h[k] = notifier.listening?(k) }
112
+ class Service
113
+ attr_reader :notifier, :instrumenter
113
114
 
114
- class << self
115
- attr_accessor :notifier
115
+ def initialize(notifier)
116
+ @notifier = notifier
117
+ @instrumenter = Instrumenter.new(notifier)
118
+ @instrumenters = Hash.new { |h,k| h[k] = notifier.listening?(k) }
119
+ end
116
120
 
117
121
  def publish(name, *args)
118
- notifier.publish(name, *args)
122
+ @notifier.publish(name, *args)
119
123
  end
120
124
 
121
125
  def instrument(name, payload = {})
122
126
  if @instrumenters[name]
123
- instrumenter.instrument(name, payload) { yield payload if block_given? }
127
+ @instrumenter.instrument(name, payload) { yield payload if block_given? }
124
128
  else
125
129
  yield payload if block_given?
126
130
  end
127
131
  end
128
132
 
129
133
  def subscribe(*args, &block)
130
- notifier.subscribe(*args, &block).tap do
134
+ @notifier.subscribe(*args, &block).tap do
131
135
  @instrumenters.clear
132
136
  end
133
137
  end
134
138
 
135
- def subscribed(callback, *args, &block)
139
+ def subscribed(callback, *args)
136
140
  subscriber = subscribe(*args, &callback)
137
141
  yield
138
142
  ensure
@@ -140,12 +144,45 @@ module ActiveSupport
140
144
  end
141
145
 
142
146
  def unsubscribe(args)
143
- notifier.unsubscribe(args)
147
+ @notifier.unsubscribe(args)
144
148
  @instrumenters.clear
145
149
  end
146
150
 
147
151
  def instrumenter
148
- Thread.current[:"instrumentation_#{notifier.object_id}"] ||= Instrumenter.new(notifier)
152
+ Thread.current[:"instrumentation_#{@notifier.object_id}"] ||= Instrumenter.new(@notifier)
153
+ end
154
+ end
155
+
156
+ class << self
157
+ attr_reader :service, :notifier
158
+
159
+ def publish(name, *args)
160
+ service.publish(name, *args)
161
+ end
162
+
163
+ def instrument(name, payload = {}, &block)
164
+ service.instrument(name, payload, &block)
165
+ end
166
+
167
+ def subscribe(*args, &block)
168
+ service.subscribe(*args, &block)
169
+ end
170
+
171
+ def subscribed(callback, *args, &block)
172
+ service.subscribed(callback, *args, &block)
173
+ end
174
+
175
+ def unsubscribe(args)
176
+ service.unsubscribe(args)
177
+ end
178
+
179
+ def instrumenter
180
+ service.instrumenter
181
+ end
182
+
183
+ def notifier=(value)
184
+ @service = Service.new(value)
185
+ @notifier = value
149
186
  end
150
187
  end
151
188
 
@@ -4,7 +4,7 @@ if ActiveSupport::VERSION::MAJOR > 2
4
4
  end
5
5
 
6
6
  module ActiveSupportNotificationsBackport
7
- VERSION = "0.0.3"
7
+ VERSION = "0.0.4"
8
8
  end
9
9
 
10
10
  require 'active_support/secure_random'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activesupport_notifications_backport
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-03-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70237287173860 !ruby/object:Gem::Requirement
16
+ requirement: &70219793442680 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - <
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70237287173860
24
+ version_requirements: *70219793442680
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70237287172200 !ruby/object:Gem::Requirement
27
+ requirement: &70219793442300 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70237287172200
35
+ version_requirements: *70219793442300
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: mocha
38
- requirement: &70237287171180 !ruby/object:Gem::Requirement
38
+ requirement: &70219793441840 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70237287171180
46
+ version_requirements: *70219793441840
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: test-unit
49
- requirement: &70237287170320 !ruby/object:Gem::Requirement
49
+ requirement: &70219793441420 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70237287170320
57
+ version_requirements: *70219793441420
58
58
  description: ActiveSupport::Notifications backported for Rails 2.3
59
59
  email: technoweenie@gmail.com
60
60
  executables: []