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.


141
142
143
# File 'lib/shrine/plugins/instrumentation.rb', line 141

def initialize(notifications)
  @notifications = notifications
end

Instance Attribute Details

#notificationsObject (readonly)

Returns the value of attribute notifications.


139
140
141
# File 'lib/shrine/plugins/instrumentation.rb', line 139

def notifications
  @notifications
end

Instance Method Details

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


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

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

#subscribe(event_name, &block) ⇒ Object


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

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