Module: Spree::Event::Adapters::ActiveSupportNotifications

Extended by:
ActiveSupportNotifications
Included in:
ActiveSupportNotifications
Defined in:
lib/spree/event/adapters/active_support_notifications.rb

Instance Method Summary collapse

Instance Method Details

#fire(event_name, opts) ⇒ Object



9
10
11
12
13
# File 'lib/spree/event/adapters/active_support_notifications.rb', line 9

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

#listeners_for(names) ⇒ Object



26
27
28
29
30
31
# File 'lib/spree/event/adapters/active_support_notifications.rb', line 26

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

#subscribe(event_name) ⇒ Object



15
16
17
18
19
20
# File 'lib/spree/event/adapters/active_support_notifications.rb', line 15

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



22
23
24
# File 'lib/spree/event/adapters/active_support_notifications.rb', line 22

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