Class: Pgtk::Wire::Yaml
- Inherits:
-
Object
- Object
- Pgtk::Wire::Yaml
- Defined in:
- lib/pgtk/wire.rb
Overview
Using configuration from YAML file.
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2019-2024 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
-
#connection ⇒ Object
Create a new connection to PostgreSQL server.
-
#initialize(file, node = 'pgsql') ⇒ Yaml
constructor
Constructor.
Constructor Details
#initialize(file, node = 'pgsql') ⇒ Yaml
Constructor.
92 93 94 95 96 97 |
# 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 |
Instance Method Details
#connection ⇒ Object
Create a new connection to PostgreSQL server.
100 101 102 103 104 105 106 107 108 109 110 |
# 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 |