Class: Shrine::Plugins::Instrumentation::Notifications

Inherits:
Object
  • Object
show all
Defined in:
lib/shrine/plugins/instrumentation.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(notifications) ⇒ Notifications

Returns a new instance of Notifications.



145
146
147
# File 'lib/shrine/plugins/instrumentation.rb', line 145

def initialize(notifications)
  @notifications = notifications
end

Instance Attribute Details

#notificationsObject (readonly)

Returns the value of attribute notifications.



143
144
145
# File 'lib/shrine/plugins/instrumentation.rb', line 143

def notifications
  @notifications
end

Instance Method Details

#instrument(event_name, payload, &block) ⇒ Object



155
156
157
# File 'lib/shrine/plugins/instrumentation.rb', line 155

def instrument(event_name, payload, &block)
  notifications.instrument(event_name, payload, &block)
end

#subscribe(event_name, &block) ⇒ Object



149
150
151
152
153
# 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