Class: Pgtk::Wire::Yaml
- Inherits:
-
Object
- Object
- Pgtk::Wire::Yaml
- Defined in:
- lib/pgtk/wire/yaml.rb
Overview
Using configuration from YAML file.
- Author
Yegor Bugayenko (yegor256@gmail.com)
- Copyright
Copyright (c) 2019-2026 Yegor Bugayenko
- License
MIT
Instance Method Summary collapse
-
#connection ⇒ Object
Create a new connection to PostgreSQL server.
-
#initialize(file, node = 'pgsql', **opts) ⇒ Yaml
constructor
Constructor.
Constructor Details
#initialize(file, node = 'pgsql', **opts) ⇒ Yaml
Constructor.
24 25 26 27 28 29 30 |
# File 'lib/pgtk/wire/yaml.rb', line 24 def initialize(file, node = 'pgsql', **opts) raise(ArgumentError, "The name of the file can't be nil") if file.nil? @file = file raise(ArgumentError, "The name of the node in the YAML file can't be nil") if node.nil? @node = node @opts = opts end |
Instance Method Details
#connection ⇒ Object
Create a new connection to PostgreSQL server.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/pgtk/wire/yaml.rb', line 33 def connection raise(ArgumentError, "The file #{@file.inspect} not found") unless File.exist?(@file) cfg = ::YAML.load_file(@file) raise(ArgumentError, "The node '#{@node}' not found in YAML file #{@file.inspect}") unless cfg[@node] Pgtk::Wire::Direct.new( host: cfg[@node]['host'], port: cfg[@node]['port'], dbname: cfg[@node]['dbname'], user: cfg[@node]['user'], password: cfg[@node]['password'], **cfg[@node].except(*%w[host port dbname user password url]).transform_keys(&:to_sym), **@opts ).connection end |