Skip to content

Commit 3c1bec4

Browse files
committed
Move AllMessages behaviour into Matcher
This avoids needing to delegate all methods to the actual subscriber class and we can deal just with the message name matching behaviour.
1 parent daa78a6 commit 3c1bec4

File tree

1 file changed

+18
-37
lines changed
  • activesupport/lib/active_support/notifications

1 file changed

+18
-37
lines changed

activesupport/lib/active_support/notifications/fanout.rb

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -108,23 +108,20 @@ def self.new(pattern, listener, monotonic)
108108
end
109109
end
110110

111-
wrap_all pattern, subscriber_class.new(pattern, listener)
112-
end
113-
114-
def self.wrap_all(pattern, subscriber)
115-
unless pattern
116-
AllMessages.new(subscriber)
117-
else
118-
subscriber
119-
end
111+
subscriber_class.new(pattern, listener)
120112
end
121113

122114
class Matcher # :nodoc:
123115
attr_reader :pattern, :exclusions
124116

125117
def self.wrap(pattern)
126-
return pattern if String === pattern
127-
new(pattern)
118+
if String === pattern
119+
pattern
120+
elsif pattern.nil?
121+
AllMessages.new
122+
else
123+
new(pattern)
124+
end
128125
end
129126

130127
def initialize(pattern)
@@ -139,6 +136,16 @@ def unsubscribe!(name)
139136
def ===(name)
140137
pattern === name && !exclusions.include?(name)
141138
end
139+
140+
class AllMessages
141+
def ===(name)
142+
true
143+
end
144+
145+
def unsubscribe!(*)
146+
false
147+
end
148+
end
142149
end
143150

144151
class Evented # :nodoc:
@@ -241,32 +248,6 @@ def build_event(name, id, payload)
241248
ActiveSupport::Notifications::Event.new name, nil, nil, id, payload
242249
end
243250
end
244-
245-
class AllMessages # :nodoc:
246-
def initialize(delegate)
247-
@delegate = delegate
248-
end
249-
250-
def start(name, id, payload)
251-
@delegate.start name, id, payload
252-
end
253-
254-
def finish(name, id, payload)
255-
@delegate.finish name, id, payload
256-
end
257-
258-
def publish(name, *args)
259-
@delegate.publish name, *args
260-
end
261-
262-
def subscribed_to?(name)
263-
true
264-
end
265-
266-
def unsubscribe!(*)
267-
false
268-
end
269-
end
270251
end
271252
end
272253
end

0 commit comments

Comments
 (0)