class Pgtk::Wire::Env
Using ENV variable.
- Author
-
Yegor Bugayenko (yegor256@gmail.com)
- Copyright
-
Copyright © 2019 Yegor Bugayenko
- License
-
MIT
Public Class Methods
new(var = 'DATABASE_URL')
click to toggle source
Constructor.
# File lib/pgtk/wire.rb, line 66 def initialize(var = 'DATABASE_URL') raise "The name of the environmant variable can't be nil" if var.nil? @var = var end
Public Instance Methods
connection()
click to toggle source
Create a new connection to PostgreSQL server.
# File lib/pgtk/wire.rb, line 72 def connection v = ENV[@var] raise "The environment variable #{@var.inspect} is not set" if v.nil? uri = URI(v) Pgtk::Wire::Direct.new( host: uri.host, port: uri.port, dbname: uri.path[1..-1], user: uri.userinfo.split(':')[0], password: uri.userinfo.split(':')[1] ).connection end