Class: Datadog::Vendor::ActiveRecord::ConnectionAdapters::ConnectionSpecification::ConnectionUrlResolver
- Inherits:
-
Object
- Object
- Datadog::Vendor::ActiveRecord::ConnectionAdapters::ConnectionSpecification::ConnectionUrlResolver
- Defined in:
- lib/ddtrace/vendor/active_record/connection_specification.rb
Overview
Expands a connection string into a hash.
Instance Method Summary collapse
-
#initialize(url) ⇒ ConnectionUrlResolver
constructor
== Example.
-
#to_hash ⇒ Object
Converts the given URL to a full connection hash.
Constructor Details
#initialize(url) ⇒ ConnectionUrlResolver
== Example
url = "postgresql://foo:bar@localhost:9000/foo_test?pool=5&timeout=3000" ConnectionUrlResolver.new(url).to_hash # => { "adapter" => "postgresql", "host" => "localhost", "port" => 9000, "database" => "foo_test", "username" => "foo", "password" => "bar", "pool" => "5", "timeout" => "3000" }
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ddtrace/vendor/active_record/connection_specification.rb', line 51 def initialize(url) raise "Database URL cannot be empty" if url.blank? @uri = uri_parser.parse(url) @adapter = @uri.scheme && @uri.scheme.tr("-", "_") @adapter = "postgresql" if @adapter == "postgres" if @uri.opaque @uri.opaque, @query = @uri.opaque.split("?", 2) else @query = @uri.query end end |
Instance Method Details
#to_hash ⇒ Object
Converts the given URL to a full connection hash.
65 66 67 68 69 |
# File 'lib/ddtrace/vendor/active_record/connection_specification.rb', line 65 def to_hash config = raw_config.reject { |_, value| value.blank? } config.map { |key, value| config[key] = uri_parser.unescape(value) if value.is_a? String } config end |