Skip to content

Commit 8248a71

Browse files
committed
Use concise syntax for defining multiple class methods
1 parent c1d1136 commit 8248a71

1 file changed

Lines changed: 17 additions & 15 deletions

File tree

app/helpers/flex/event_manager.rb

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
module Flex
22
class EventManager
3-
def self.subscribe(event_key, callback)
4-
subscription = ActiveSupport::Notifications.subscribe(event_key) do |name, _started, _finished, _unique_id, payload|
5-
callback.call({
6-
name: name,
7-
payload: payload
8-
})
9-
end
3+
class << self
4+
def subscribe(event_key, callback)
5+
subscription = ActiveSupport::Notifications.subscribe(event_key) do |name, _started, _finished, _unique_id, payload|
6+
callback.call({
7+
name: name,
8+
payload: payload
9+
})
10+
end
1011

11-
subscription
12-
end
12+
subscription
13+
end
1314

14-
def self.unsubscribe(subscription)
15-
ActiveSupport::Notifications.unsubscribe(subscription)
16-
end
15+
def unsubscribe(subscription)
16+
ActiveSupport::Notifications.unsubscribe(subscription)
17+
end
1718

18-
def self.publish(event_key, payload = {})
19-
puts "Event Manager: Publishing event '#{event_key}' with payload: #{payload.inspect}"
20-
ActiveSupport::Notifications.instrument(event_key, payload)
19+
def publish(event_key, payload = {})
20+
puts "Event Manager: Publishing event '#{event_key}' with payload: #{payload.inspect}"
21+
ActiveSupport::Notifications.instrument(event_key, payload)
22+
end
2123
end
2224

2325
private

0 commit comments

Comments
 (0)