Module: Watchforge::DSN

Defined in:
lib/watchforge/dsn.rb

Class Method Summary collapse

Class Method Details

.parse(dsn) ⇒ Object

Raises:

  • (ArgumentError)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/watchforge/dsn.rb', line 30

def parse(dsn)
  uri = URI.parse(dsn)
  raise ArgumentError, "invalid watchforge dsn" if uri.user.nil? || uri.host.nil? || uri.path.nil? || uri.path == "/"

  scheme = %w[localhost 127.0.0.1].include?(uri.host) ? "http" : uri.scheme
  ParsedDSN.new(
    scheme: scheme,
    public_key: uri.user,
    host: uri.host,
    port: uri.port,
    project_id: uri.path.delete_prefix("/"),
    dsn: dsn
  )
end