Sha256: edab74aa14704202b4b609397c985f404ce2ebab31ebede02b7ff223ec06af20

Contents?: true

Size: 1.46 KB

Versions: 48

Compression:

Stored size: 1.46 KB

Contents

require 'ddtrace/contrib/configuration/resolver'
require 'ddtrace/vendor/active_record/connection_specification'

module Datadog
  module Contrib
    module ActiveRecord
      module Configuration
        # Converts Symbols, Strings, and Hashes to a normalized connection settings Hash.
        class Resolver < Contrib::Configuration::Resolver
          def initialize(configurations = nil)
            @configurations = configurations
          end

          def configurations
            @configurations || ::ActiveRecord::Base.configurations
          end

          def connection_resolver
            @resolver ||= begin
              if defined?(::ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver)
                ::ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new(configurations)
              else
                ::Datadog::Vendor::ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new(configurations)
              end
            end
          end

          def resolve(spec)
            return :default if spec == :default
            normalize(connection_resolver.resolve(spec).symbolize_keys)
          end

          def normalize(hash)
            {
              adapter:  hash[:adapter],
              host:     hash[:host],
              port:     hash[:port],
              database: hash[:database],
              username: hash[:username]
            }
          end
        end
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 2 rubygems

Version Path
ls-trace-0.1.2 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.32.0 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.31.1 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.31.0 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.30.1 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.30.0 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.29.1 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.26.1 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ls-trace-0.1.1 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.29.0 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.28.0 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.27.0 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.26.0 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.25.1 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.25.0 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.24.0 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.23.3 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.23.2 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.23.1 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.23.0 lib/ddtrace/contrib/active_record/configuration/resolver.rb