class Datadog::Contrib::ActiveSupport::Notifications::Subscription::Callbacks

Wrapper for subscription callbacks

Attributes

blocks[R]

Public Class Methods

new() click to toggle source
# File lib/ddtrace/contrib/active_support/notifications/subscription.rb, line 129
def initialize
  @blocks = {}
end

Public Instance Methods

add(key, &block) click to toggle source
# File lib/ddtrace/contrib/active_support/notifications/subscription.rb, line 133
def add(key, &block)
  blocks_for(key) << block if block_given?
end
run(event, key, *args) click to toggle source
# File lib/ddtrace/contrib/active_support/notifications/subscription.rb, line 137
def run(event, key, *args)
  blocks_for(key).each do |callback|
    begin
      callback.call(event, key, *args)
    rescue StandardError => e
      Datadog.logger.debug(
        "ActiveSupport::Notifications '#{key}' callback for '#{event}' failed: #{e.message}"
      )
    end
  end
end

Private Instance Methods

blocks_for(key) click to toggle source
# File lib/ddtrace/contrib/active_support/notifications/subscription.rb, line 151
def blocks_for(key)
  blocks[key] ||= []
end