Sha256: 566b0168307c5db0d45ff2c7705d975290fc0570c2c1a677df412da67176e01e

Contents?: true

Size: 873 Bytes

Versions: 7

Compression:

Stored size: 873 Bytes

Contents

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

7 entries across 7 versions & 1 rubygems

Version Path
ddtrace-0.51.1 lib/ddtrace/contrib/registry.rb
ddtrace-0.51.0 lib/ddtrace/contrib/registry.rb
ddtrace-0.50.0 lib/ddtrace/contrib/registry.rb
ddtrace-0.49.0 lib/ddtrace/contrib/registry.rb
ddtrace-0.48.0 lib/ddtrace/contrib/registry.rb
ddtrace-0.47.0 lib/ddtrace/contrib/registry.rb
ddtrace-0.46.0 lib/ddtrace/contrib/registry.rb