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.



147
148
149
# File 'lib/shrine/plugins/instrumentation.rb', line 147

def initialize(notifications)
  @notifications = notifications
end

Instance Attribute Details

#notificationsObject (readonly)

Returns the value of attribute notifications.



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

def notifications
  @notifications
end

Instance Method Details

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



157
158
159
# File 'lib/shrine/plugins/instrumentation.rb', line 157

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

#subscribe(event_name, &block) ⇒ Object



151
152
153
154
155
# File 'lib/shrine/plugins/instrumentation.rb', line 151

def subscribe(event_name, &block)
  library_send(:subscribe, event_name) do |event|
    yield Event.new(event)
  end
end