class Shrine::Plugins::Instrumentation::Notifications

Abstracts away different types of notifications objects (‘ActiveSupport::Notifications` and `Dry::Monitor::Notifications`).

Attributes

notifications[R]

Public Class Methods

new(notifications) click to toggle source
# File lib/shrine/plugins/instrumentation.rb, line 145
def initialize(notifications)
  @notifications = notifications
end

Public Instance Methods

instrument(event_name, payload, &block) click to toggle source
# File lib/shrine/plugins/instrumentation.rb, line 155
def instrument(event_name, payload, &block)
  notifications.instrument(event_name, payload, &block)
end
subscribe(event_name) { |event| ... } click to toggle source
# File lib/shrine/plugins/instrumentation.rb, line 149
def subscribe(event_name, &block)
  library_send(:subscribe, event_name) do |event|
    yield Event.new(event)
  end
end

Private Instance Methods

active_support_subscribe(event_name) { |event(*args)| ... } click to toggle source
# File lib/shrine/plugins/instrumentation.rb, line 166
def active_support_subscribe(event_name, &block)
  notifications.subscribe(event_name) do |*args|
    yield ActiveSupport::Notifications::Event.new(*args)
  end
end
dry_monitor_subscribe(event_name, &block) click to toggle source
# File lib/shrine/plugins/instrumentation.rb, line 161
def dry_monitor_subscribe(event_name, &block)
  notifications.register_event(event_name)
  notifications.subscribe(event_name, &block)
end
library_send(method_name, *args, &block) click to toggle source
# File lib/shrine/plugins/instrumentation.rb, line 172
def library_send(method_name, *args, &block)
  case notifications.to_s
  when /Dry::Monitor::Notifications/
    send(:"dry_monitor_#{method_name}", *args, &block)
  when /ActiveSupport::Notifications/
    send(:"active_support_#{method_name}", *args, &block)
  else
    notifications.send(method_name, *args, &block)
  end
end