lib/dbi/dbrc.rb in dbi-dbrc-1.6.0 vs lib/dbi/dbrc.rb in dbi-dbrc-1.7.0
- old
+ new
@@ -15,11 +15,11 @@
class DBRC
# This error is raised if anything fails trying to read the config file.
class Error < StandardError; end
# The version of the dbi-dbrc library
- VERSION = '1.6.0'
+ VERSION = '1.7.0'
WINDOWS = File::ALT_SEPARATOR # :no-doc:
# The database or host to be connected to.
attr_accessor :database
@@ -102,11 +102,11 @@
# DBI::DBRC.new('some_database', 'foo_usr', '/usr/local')
#
# # Pass along a GPG password to decrypt the file.
# DBI::DBRC.new('some_database', 'foo_usr', '/usr/local', :gpg_options => {:password => 'xxx'})
#
- def initialize(database, user = nil, dbrc_dir = Dir.home, gpg_options = nil)
+ def initialize(database, user = nil, dbrc_dir = Dir.home, gpg_options = nil)
if dbrc_dir.nil?
# Default to the app data directory on Windows, or root on Unix, if
# no home dir can be found.
if home.nil?
if WINDOWS
@@ -243,64 +243,10 @@
else
raise Error, "no record found for #{@database}" unless @database
end
end
end
-
- # A subclass of DBRC designed to handle .dbrc files in XML format. The
- # public methods of this class are identical to DBRC.
- class DBRC::XML < DBRC
- require 'rexml/document' # Good enough for small files
-
- private
-
- def parse_dbrc_config_file(file = @dbrc_file)
- file = file.is_a?(StringIO) ? file : File.new(file)
- doc = REXML::Document.new(file)
-
- fields = %w[user password driver interval timeout maximum_reconnects]
-
- doc.elements.each('/dbrc/database') do |element|
- next unless element.attributes['name'] == database
- next if @user && @user != element.elements['user'].text
-
- fields.each do |field|
- val = element.elements[field]
- send("#{field}=", val.text) unless val.nil?
- end
-
- break
- end
-
- raise Error, "No record found for #{@user}@#{@database}" unless @user && @database
- end
- end
-
- # 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
+
+require_relative 'dbrc/xml'
+require_relative 'dbrc/yaml'
+require_relative 'dbrc/json'