Sha256: ea2a2db9dcb7542b9a7773a08d08d7a5c69fac84797e723662b200d163a32241

Contents?: true

Size: 1019 Bytes

Versions: 1

Compression:

Stored size: 1019 Bytes

Contents

# frozen_string_literal: true

require_relative '../dbrc'

# The DBI module serves as namespace only.
module DBI
  # A subclass of DBRC designed to handle .dbrc files in YAML format. The
  # public methods of this class are identical to DBRC.
  class DBRC::YML < DBRC
    require 'yaml'

    private

    def parse_dbrc_config_file(file = @dbrc_file)
      fh = file.is_a?(StringIO) ? file : File.open(file)
      config = ::YAML.safe_load(fh)

      config.each do |hash|
        hash.each do |db, info|
          next unless db == @database
          next if @user && @user != info['user']
          @user = info['user']
          @password = info['password']
          @driver = info['driver']
          @interval = info['interval']
          @timeout = info['timeout']
          @maximum_reconnects = info['maximum_reconnects']
          break
        end
      end

      raise Error, "No entry found for #{@user}@#{@database}" unless @user && @database
    end
  end
end

DBI::DBRC::YAML = DBI::DBRC::YML # Alias

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dbi-dbrc-1.7.0 lib/dbi/dbrc/yaml.rb