Skip to content

Commit 8730f04

Browse files
committed
#276: Refactor environment variable handling in Pgtk::Wire::Env.
1 parent f78bd2e commit 8730f04

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

lib/pgtk/wire.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,13 @@ class Pgtk::Wire::Env
6161
# @param [String] var The name of the environment variable with the connection URL
6262
def initialize(var = 'DATABASE_URL')
6363
raise "The name of the environment variable can't be nil" if var.nil?
64-
@var = var
64+
@value = ENV.fetch(var, nil)
65+
raise "The environment variable #{@value.inspect} is not set" if @value.nil?
6566
end
6667

6768
# Create a new connection to PostgreSQL server.
6869
def connection
69-
v = ENV.fetch(@var, nil)
70-
raise "The environment variable #{@var.inspect} is not set" if v.nil?
71-
uri = URI(v)
70+
uri = URI(@value)
7271
Pgtk::Wire::Direct.new(
7372
host: CGI.unescape(uri.host),
7473
port: uri.port,

0 commit comments

Comments
 (0)