Skip to content

Commit

Permalink
#20 checks
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Oct 20, 2019
1 parent 5404380 commit 88dc611
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/pgtk/wire.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ module Pgtk::Wire
class Pgtk::Wire::Direct
# Constructor.
def initialize(host:, port:, dbname:, user:, password:)
raise "The host can't be nil" if host.nil?
@host = host
raise "The host can't be nil" if host.nil?
@port = port
@dbname = dbname
@user = user
Expand All @@ -62,12 +64,15 @@ def connection
class Pgtk::Wire::Env
# Constructor.
def initialize(var = 'DATABASE_URL')
raise "The name of the environmant variable can't be nil" if var.nil?
@var = var
end

# Create a new connection to PostgreSQL server.
def connection
uri = URI(ENV[@var])
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,
Expand All @@ -85,12 +90,15 @@ def connection
class Pgtk::Wire::Yaml
# Constructor.
def initialize(file, node = 'pgsql')
raise "The name of the file can't be nil" if file.nil?
@file = file
raise "The name of the node in the YAML file can't be nil" if node.nil?
@node = node
end

# Create a new connection to PostgreSQL server.
def connection
raise "The file #{@file.inspect} not found" unless File.exist?(@file)
cfg = YAML.load_file(@file)
Pgtk::Wire::Direct.new(
host: cfg['pgsql']['host'],
Expand Down

0 comments on commit 88dc611

Please sign in to comment.