Class: Datadog::Contrib::ActiveRecord::Configuration::Resolver
- Inherits:
-
Configuration::Resolver
- Object
- Configuration::Resolver
- Datadog::Contrib::ActiveRecord::Configuration::Resolver
- Defined in:
- lib/ddtrace/contrib/active_record/configuration/resolver.rb
Overview
Converts Symbols, Strings, and Hashes to a normalized connection settings Hash.
Instance Method Summary collapse
- #configurations ⇒ Object
- #connection_resolver ⇒ Object
-
#initialize(configurations = nil) ⇒ Resolver
constructor
A new instance of Resolver.
- #normalize(hash) ⇒ Object
- #resolve(spec) ⇒ Object
Constructor Details
#initialize(configurations = nil) ⇒ Resolver
Returns a new instance of Resolver.
10 11 12 |
# File 'lib/ddtrace/contrib/active_record/configuration/resolver.rb', line 10 def initialize(configurations = nil) @configurations = configurations end |
Instance Method Details
#configurations ⇒ Object
14 15 16 |
# File 'lib/ddtrace/contrib/active_record/configuration/resolver.rb', line 14 def configurations @configurations || ::ActiveRecord::Base.configurations end |
#connection_resolver ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/ddtrace/contrib/active_record/configuration/resolver.rb', line 18 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 |
#normalize(hash) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/ddtrace/contrib/active_record/configuration/resolver.rb', line 33 def normalize(hash) { adapter: hash[:adapter], host: hash[:host], port: hash[:port], database: hash[:database], username: hash[:username] } end |
#resolve(spec) ⇒ Object
28 29 30 31 |
# File 'lib/ddtrace/contrib/active_record/configuration/resolver.rb', line 28 def resolve(spec) return :default if spec == :default normalize(connection_resolver.resolve(spec).symbolize_keys) end |