Module: Panda::Core::Notifications

Defined in:
lib/panda/core/notifications.rb

Constant Summary collapse

USER_CREATED =

Event names following Rails convention: namespace.event

"panda.core.user_created"
USER_LOGIN =
"panda.core.user_login"
USER_LOGOUT =
"panda.core.user_logout"
ADMIN_ACTION =
"panda.core.admin_action"

Class Method Summary collapse

Class Method Details

.instrument(event_name, payload = {}) ⇒ Object

Instrument a Panda Core event

Examples:

Panda::Core::Notifications.instrument(:user_created, user: user, provider: provider)


28
29
30
31
# File 'lib/panda/core/notifications.rb', line 28

def instrument(event_name, payload = {})
  event_key = const_get(event_name.to_s.upcase)
  ActiveSupport::Notifications.instrument(event_key, payload)
end

.subscribe(event_name, &block) ⇒ Object

Subscribe to a Panda Core event

Examples:

Panda::Core::Notifications.subscribe(:user_created) do |event|
  UserMailer.welcome(event.payload[:user]).deliver_later
end


19
20
21
22
# File 'lib/panda/core/notifications.rb', line 19

def subscribe(event_name, &block)
  event_key = const_get(event_name.to_s.upcase)
  ActiveSupport::Notifications.subscribe(event_key, &block)
end

.unsubscribe(subscriber) ⇒ Object

Unsubscribe from a Panda Core event



34
35
36
# File 'lib/panda/core/notifications.rb', line 34

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