Sha256: d748420bbf00cd3b45f2c0afffc14e5a9b0e53a22e44b391f78f7e59aa7a1c55

Contents?: true

Size: 887 Bytes

Versions: 5

Compression:

Stored size: 887 Bytes

Contents

# typed: true
module Datadog
  module Contrib
    # Registry is a collection of integrations.
    class Registry
      include Enumerable

      Entry = Struct.new(:name, :klass, :auto_patch)

      def initialize
        @data = {}
        @mutex = Mutex.new
      end

      def add(name, klass, auto_patch = false)
        @mutex.synchronize do
          @data[name] = Entry.new(name, klass, auto_patch).freeze
        end
      end

      def each(&block)
        @mutex.synchronize do
          @data.each_value(&block)
        end
      end

      def [](name)
        @mutex.synchronize do
          entry = @data[name]
          entry.klass if entry
        end
      end

      def to_h
        @mutex.synchronize do
          @data.each_with_object({}) do |(_, entry), hash|
            hash[entry.name] = entry.auto_patch
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ddtrace-0.54.2 lib/ddtrace/contrib/registry.rb
ddtrace-0.54.1 lib/ddtrace/contrib/registry.rb
ddtrace-0.54.0 lib/ddtrace/contrib/registry.rb
ddtrace-0.53.0 lib/ddtrace/contrib/registry.rb
ddtrace-0.52.0 lib/ddtrace/contrib/registry.rb