Class: Pgtk::Wire::Yaml

Inherits:
Object
  • Object
show all
Defined in:
lib/pgtk/wire.rb

Overview

Using configuration from YAML file.

Author

Yegor Bugayenko ([email protected])

Copyright

Copyright © 2019 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(file, node = 'pgsql') ⇒ Yaml

Constructor.



87
88
89
90
# File 'lib/pgtk/wire.rb', line 87

def initialize(file, node = 'pgsql')
  @file = file
  @node = node
end

Instance Method Details

#connectionObject

Create a new connection to PostgreSQL server.



93
94
95
96
97
98
99
100
101
102
# File 'lib/pgtk/wire.rb', line 93

def connection
  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