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.



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

def initialize(notifications)
  @notifications = notifications
end

Instance Attribute Details

#notificationsObject (readonly)

Returns the value of attribute notifications.



136
137
138
# File 'lib/shrine/plugins/instrumentation.rb', line 136

def notifications
  @notifications
end

Instance Method Details

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



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

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

#subscribe(event_name, &block) ⇒ Object



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

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