Module: ActivePubsubRails::Adapters::ActiveSupportNotifications

Defined in:
lib/active_pubsub_rails/adapters/active_support_notifications.rb

Defined Under Namespace

Classes: InvalidEventNameType

Class Method Summary collapse

Class Method Details

.fire(event_name, opts) ⇒ Object



10
11
12
13
14
# File 'lib/active_pubsub_rails/adapters/active_support_notifications.rb', line 10

def fire(event_name, opts)
  ActiveSupport::Notifications.instrument event_name, opts do
    yield opts if block_given?
  end
end

.listeners_for(names) ⇒ Object



27
28
29
30
31
32
# File 'lib/active_pubsub_rails/adapters/active_support_notifications.rb', line 27

def listeners_for(names)
  names.each_with_object({}) do |name, memo|
    listeners = ActiveSupport::Notifications.notifier.listeners_for(name)
    memo[name] = listeners if listeners.present?
  end
end

.normalize_name(event_name) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/active_pubsub_rails/adapters/active_support_notifications.rb', line 34

def normalize_name(event_name)
  case event_name
  when Regexp, String, Symbol
    event_name
  else
    raise InvalidEventNameType, "Invalid event name type: #{event_name.class}"
  end
end

.subscribe(event_name) ⇒ Object



16
17
18
19
20
21
# File 'lib/active_pubsub_rails/adapters/active_support_notifications.rb', line 16

def subscribe(event_name)
  ActiveSupport::Notifications.subscribe event_name do |*args|
    event = ActiveSupport::Notifications::Event.new(*args)
    yield event
  end
end

.unsubscribe(subscriber_or_name) ⇒ Object



23
24
25
# File 'lib/active_pubsub_rails/adapters/active_support_notifications.rb', line 23

def unsubscribe(subscriber_or_name)
  ActiveSupport::Notifications.unsubscribe(subscriber_or_name)
end