Module: Polyrun::Database::UrlBuilder::ConnectionUrlBuilders

Defined in:
lib/polyrun/database/url_builder/connection/url_builders.rb

Overview

String construction for DATABASE_URL values.

Class Method Summary collapse

Class Method Details

.build_mongodb_url(host, port, user, password, database) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/polyrun/database/url_builder/connection/url_builders.rb', line 27

def build_mongodb_url(host, port, user, password, database)
  if user.to_s.empty?
    return "mongodb://#{host}:#{port}/#{database}"
  end

  u = URI.encode_www_form_component(user.to_s)
  if password && !password.to_s.empty?
    p = URI.encode_www_form_component(password.to_s)
    "mongodb://#{u}:#{p}@#{host}:#{port}/#{database}"
  else
    "mongodb://#{u}@#{host}:#{port}/#{database}"
  end
end

.build_sqlite_url(database) ⇒ Object



10
11
12
# File 'lib/polyrun/database/url_builder/connection/url_builders.rb', line 10

def build_sqlite_url(database)
  "sqlite3:#{database}"
end

.build_url_authority(scheme, host, port, user, password, database) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/polyrun/database/url_builder/connection/url_builders.rb', line 14

def build_url_authority(scheme, host, port, user, password, database)
  if password && !password.to_s.empty?
    u = URI.encode_www_form_component(user.to_s)
    p = URI.encode_www_form_component(password.to_s)
    "#{scheme}://#{u}:#{p}@#{host}:#{port}/#{database}"
  elsif !user.to_s.empty?
    u = URI.encode_www_form_component(user.to_s)
    "#{scheme}://#{u}@#{host}:#{port}/#{database}"
  else
    "#{scheme}://#{host}:#{port}/#{database}"
  end
end