module Datadog::Contrib::ActiveSupport::Notifications::Subscriber::ClassMethods

Class methods that are implemented in the inheriting class.

Attributes

on_subscribe_block[R]
subscribed[R]

Public Instance Methods

subscribed?() click to toggle source

Returns whether subscriptions have been activated, via subscribe!

# File lib/ddtrace/contrib/active_support/notifications/subscriber.rb, line 24
def subscribed?
  subscribed == true
end
subscriptions() click to toggle source

Returns a list of subscriptions created for this class.

# File lib/ddtrace/contrib/active_support/notifications/subscriber.rb, line 19
def subscriptions
  @subscriptions ||= Set.new
end

Protected Instance Methods

on_subscribe(&block) click to toggle source

Defines a callback for when subscribe! is called. Should contain subscription setup, defined by the inheriting class.

# File lib/ddtrace/contrib/active_support/notifications/subscriber.rb, line 32
def on_subscribe(&block)
  @on_subscribe_block = block
end
subscribe(pattern, span_name, options = {}, tracer = -> { Datadog.tracer } click to toggle source

Creates a subscription and immediately activates it.

# File lib/ddtrace/contrib/active_support/notifications/subscriber.rb, line 46
def subscribe(pattern, span_name, options = {}, tracer = -> { Datadog.tracer }, &block)
  subscription(span_name, options, tracer, &block).tap do |subscription|
    subscription.subscribe(pattern)
  end
end
subscribe!() click to toggle source

Runs the on_subscribe callback once, to activate subscriptions. Should be triggered by the inheriting class.

# File lib/ddtrace/contrib/active_support/notifications/subscriber.rb, line 38
def subscribe!
  return subscribed? if subscribed? || on_subscribe_block.nil?

  on_subscribe_block.call
  @subscribed = true
end
subscription(span_name, options = {}, tracer = -> { Datadog.tracer } click to toggle source

Creates a subscription without activating it. Subscription is added to the inheriting class' list of subscriptions.

# File lib/ddtrace/contrib/active_support/notifications/subscriber.rb, line 54
def subscription(span_name, options = {}, tracer = -> { Datadog.tracer }, &block)
  Subscription.new(tracer, span_name, options, &block).tap do |subscription|
    subscriptions << subscription
  end
end