class Pgtk::Wire::Yaml

Using configuration from YAML file.

Author

Yegor Bugayenko (yegor256@gmail.com)

Copyright

Copyright © 2019 Yegor Bugayenko

License

MIT

Public Class Methods

new(file, node = 'pgsql') click to toggle source

Constructor.

# File lib/pgtk/wire.rb, line 92
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

Public Instance Methods

connection() click to toggle source

Create a new connection to PostgreSQL server.

# File lib/pgtk/wire.rb, line 100
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'],
    port: cfg['pgsql']['port'],
    dbname: cfg['pgsql']['dbname'],
    user: cfg['pgsql']['user'],
    password: cfg['pgsql']['password']
  ).connection
end