Sha256: 0241448fab9a48e3694cbfaf78ceea78862d7c8bd78516092c47ed310281dc7d

Contents?: true

Size: 1.41 KB

Versions: 19

Compression:

Stored size: 1.41 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 resolve(key)
            normalize(connection_resolver.resolve(key).symbolize_keys)
          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 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

19 entries across 19 versions & 2 rubygems

Version Path
ddtrace-0.45.0 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.44.0 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.43.0 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.42.0 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.41.0 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ls-trace-0.2.0 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.40.0 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.39.0 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.38.0 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.37.0 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.36.0 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.35.2 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.35.1 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.35.0 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.34.2 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.34.1 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.34.0 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.33.1 lib/ddtrace/contrib/active_record/configuration/resolver.rb
ddtrace-0.33.0 lib/ddtrace/contrib/active_record/configuration/resolver.rb