Method: ActiveRecord::ConnectionAdapters::ConnectionSpecification::ConnectionUrlResolver#initialize

Defined in:
lib/active_record/connection_adapters/connection_specification.rb

#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"
}


38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/active_record/connection_adapters/connection_specification.rb', line 38

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