Sha256: 7f2534f828ed0b001fb3e90aacbe7e0f6262378e66bddac1c4fd3eb26a7a92fe

Contents?: true

Size: 1.35 KB

Versions: 13

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

require_relative '../vendor/resolver'

module Datadog
  module Tracing
    module Contrib
      module Redis
        module Configuration
          UNIX_SCHEME = 'unix'

          # Converts String URLs and Hashes to a normalized connection settings Hash.
          class Resolver < Contrib::Configuration::Resolver
            # @param [Hash,String] Redis connection information
            def resolve(hash)
              super(parse_matcher(hash))
            end

            protected

            def parse_matcher(matcher)
              matcher = { url: matcher } if matcher.is_a?(String)

              normalize(connection_resolver.resolve(matcher))
            end

            def normalize(hash)
              return { url: hash[:url] } if hash[:scheme] == UNIX_SCHEME

              # Connexion strings are always converted to host, port, db and scheme
              # but the host, port, db and scheme will generate the :url only after
              # establishing a first connexion
              {
                host: hash[:host],
                port: hash[:port],
                db: hash[:db],
                scheme: hash[:scheme]
              }
            end

            def connection_resolver
              @connection_resolver ||= Vendor::Resolver.new
            end
          end
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
datadog-2.9.0 lib/datadog/tracing/contrib/redis/configuration/resolver.rb
datadog-2.8.0 lib/datadog/tracing/contrib/redis/configuration/resolver.rb
datadog-2.7.1 lib/datadog/tracing/contrib/redis/configuration/resolver.rb
datadog-2.7.0 lib/datadog/tracing/contrib/redis/configuration/resolver.rb
datadog-2.6.0 lib/datadog/tracing/contrib/redis/configuration/resolver.rb
datadog-2.5.0 lib/datadog/tracing/contrib/redis/configuration/resolver.rb
datadog-2.4.0 lib/datadog/tracing/contrib/redis/configuration/resolver.rb
datadog-2.3.0 lib/datadog/tracing/contrib/redis/configuration/resolver.rb
datadog-2.2.0 lib/datadog/tracing/contrib/redis/configuration/resolver.rb
datadog-2.1.0 lib/datadog/tracing/contrib/redis/configuration/resolver.rb
datadog-2.0.0 lib/datadog/tracing/contrib/redis/configuration/resolver.rb
datadog-2.0.0.beta2 lib/datadog/tracing/contrib/redis/configuration/resolver.rb
datadog-2.0.0.beta1 lib/datadog/tracing/contrib/redis/configuration/resolver.rb