dbi-dbrc 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,6 @@
1
+ == 1.1.4 - 10-Nov-2008
2
+ * Added a custom inspect method which filters the password.
3
+
1
4
  == 1.1.3 - 21-Jul-2008
2
5
  * More RUBY_PLATFORM changes that I missed in the last release.
3
6
  * Added inline RDOC for the accessors and updated the documentation
@@ -1,21 +1,21 @@
1
- ###########################################################################
2
- # test.rb
3
- #
4
- # This script is provided for those without TestUnit installed and/or for
5
- # general futzing.
6
- ###########################################################################
7
- if File.basename(Dir.pwd) == "plain"
8
- Dir.chdir "../.."
9
- $LOAD_PATH.unshift Dir.pwd + "/lib"
10
- Dir.chdir "examples/plain"
11
- end
12
-
13
- require "pp"
14
- require "dbi/dbrc"
15
- include DBI
16
-
17
- puts "VERSION: " + DBRC::VERSION
18
-
19
- db = DBRC.new("foo","user1",Dir.pwd)
20
-
21
- pp db
1
+ ###########################################################################
2
+ # test.rb
3
+ #
4
+ # This script is provided for those without TestUnit installed and/or for
5
+ # general futzing.
6
+ ###########################################################################
7
+ if File.basename(Dir.pwd) == "plain"
8
+ Dir.chdir "../.."
9
+ $LOAD_PATH.unshift Dir.pwd + "/lib"
10
+ Dir.chdir "examples/plain"
11
+ end
12
+
13
+ require "pp"
14
+ require "dbi/dbrc"
15
+ include DBI
16
+
17
+ puts "VERSION: " + DBRC::VERSION
18
+
19
+ db = DBRC.new("foo","user1",Dir.pwd)
20
+
21
+ pp db
@@ -1,28 +1,28 @@
1
- #######################################################################
2
- # test_xml.rb
3
- #
4
- # Simple test script that uses the DBRC::XML subclass.
5
- #######################################################################
6
- if File.basename(Dir.pwd) == "xml"
7
- Dir.chdir "../.."
8
- $LOAD_PATH.unshift Dir.pwd + "/lib"
9
- Dir.chdir "examples/xml"
10
- end
11
-
12
- require "dbi/dbrc"
13
- require "pp"
14
- include DBI
15
-
16
- puts "VERSION: " + DBRC::XML::VERSION
17
-
18
- # Use the .dbrc file in this directory
19
- db1 = DBRC::XML.new("foo",nil,Dir.pwd) # Get first entry found for 'foo'
20
- db2 = DBRC::XML.new("foo","user1",Dir.pwd) # Specify user
21
-
22
- puts "First entry found for 'foo': "
23
- pp db1
24
- puts "=" * 20
25
-
26
- puts "Entry for 'foo' with user 'bar': "
27
- pp db2
28
- puts "=" * 20
1
+ #######################################################################
2
+ # test_xml.rb
3
+ #
4
+ # Simple test script that uses the DBRC::XML subclass.
5
+ #######################################################################
6
+ if File.basename(Dir.pwd) == "xml"
7
+ Dir.chdir "../.."
8
+ $LOAD_PATH.unshift Dir.pwd + "/lib"
9
+ Dir.chdir "examples/xml"
10
+ end
11
+
12
+ require "dbi/dbrc"
13
+ require "pp"
14
+ include DBI
15
+
16
+ puts "VERSION: " + DBRC::XML::VERSION
17
+
18
+ # Use the .dbrc file in this directory
19
+ db1 = DBRC::XML.new("foo",nil,Dir.pwd) # Get first entry found for 'foo'
20
+ db2 = DBRC::XML.new("foo","user1",Dir.pwd) # Specify user
21
+
22
+ puts "First entry found for 'foo': "
23
+ pp db1
24
+ puts "=" * 20
25
+
26
+ puts "Entry for 'foo' with user 'bar': "
27
+ pp db2
28
+ puts "=" * 20
@@ -1,28 +1,28 @@
1
- #######################################################################
2
- # test_xml.rb
3
- #
4
- # Simple test script that uses the DBRC::XML subclass.
5
- #######################################################################
6
- if File.basename(Dir.pwd) == "yml"
7
- Dir.chdir "../.."
8
- $LOAD_PATH.unshift Dir.pwd + "/lib"
9
- Dir.chdir "examples/yml"
10
- end
11
-
12
- require "dbi/dbrc"
13
- require "pp"
14
- include DBI
15
-
16
- puts "VERSION: " + DBRC::YML::VERSION
17
-
18
- # Use the .dbrc file in this directory
19
- db1 = DBRC::YML.new("foo",nil,Dir.pwd) # Get first entry found for 'foo'
20
- db2 = DBRC::YML.new("foo","user1",Dir.pwd) # Specify user
21
-
22
- puts "First entry found for 'foo': "
23
- pp db1
24
- puts "=" * 20
25
-
26
- puts "Entry for 'foo' with user 'bar': "
27
- pp db2
28
- puts "=" * 20
1
+ #######################################################################
2
+ # test_xml.rb
3
+ #
4
+ # Simple test script that uses the DBRC::XML subclass.
5
+ #######################################################################
6
+ if File.basename(Dir.pwd) == "yml"
7
+ Dir.chdir "../.."
8
+ $LOAD_PATH.unshift Dir.pwd + "/lib"
9
+ Dir.chdir "examples/yml"
10
+ end
11
+
12
+ require "dbi/dbrc"
13
+ require "pp"
14
+ include DBI
15
+
16
+ puts "VERSION: " + DBRC::YML::VERSION
17
+
18
+ # Use the .dbrc file in this directory
19
+ db1 = DBRC::YML.new("foo",nil,Dir.pwd) # Get first entry found for 'foo'
20
+ db2 = DBRC::YML.new("foo","user1",Dir.pwd) # Specify user
21
+
22
+ puts "First entry found for 'foo': "
23
+ pp db1
24
+ puts "=" * 20
25
+
26
+ puts "Entry for 'foo' with user 'bar': "
27
+ pp db2
28
+ puts "=" * 20
@@ -1,283 +1,298 @@
1
- require 'rbconfig'
2
-
3
- if Config::CONFIG['host_os'].match('mswin')
4
- require 'win32/file'
5
- require 'win32/dir'
6
- end
7
-
8
- require 'sys/admin'
9
-
10
- # The DBI module serves as a namespace only.
11
- module DBI
12
-
13
- # The DBRC class encapsulates a database resource config file.
14
- class DBRC
15
-
16
- # This error is raised if anything fails trying to read the config file.
17
- # the error that is raised.
18
- class Error < StandardError; end
19
-
20
- # The version of this library
21
- VERSION = '1.1.3'
22
-
23
- # The database or host to be connected to.
24
- attr_accessor :database
25
-
26
- # The user name used for the database or host connection.
27
- attr_accessor :user
28
-
29
- # The password associated with the database or host.
30
- attr_accessor :password
31
-
32
- # The driver associated with the database. This is used to internally to
33
- # construct the DSN.
34
- attr_accessor :driver
35
-
36
- # Data source name, e.g. "dbi:OCI8:your_database".
37
- attr_accessor :dsn
38
-
39
- # The maximum number of reconnects a program should make before
40
- # giving up.
41
- attr_accessor :maximum_reconnects
42
-
43
- # The timeout, in seconds, for each connection attempt.
44
- attr_accessor :timeout
45
-
46
- # The interval, in seconds, between each connection attempt.
47
- attr_accessor :interval
48
-
49
- # The directory where the .dbrc file is stored.
50
- attr_accessor :dbrc_dir
51
-
52
- # The full path to the .dbrc file.
53
- attr_accessor :dbrc_file
54
-
55
- # Returns a new DBI::DBRC object. The contents of the object depend on
56
- # the arguments passed to the constructor. If only a database name is
57
- # passed, then the first entry found in the .dbrc file that matches that
58
- # database is parsed. If a user name is also included, then the first
59
- # entry that matches both the database and user name is parsed.
60
- #
61
- # If a directory is passed as the third argument, then DBRC will look
62
- # in that directory, instead of the default directory, for the .dbrc
63
- # file.
64
- #
65
- # If an entry cannot be found for the database, or database plus user
66
- # combination, then a Error is raised. If the .dbrc file cannot
67
- # be found, or is setup improperly with regards to permissions or
68
- # properties, a DBI::DBRC::Error is raised.
69
- #
70
- # See the README for the rules regarding .dbrc files and permissions.
71
- #
72
- # Note that this library can also be used as a general password
73
- # storage mechanism. In that case simply treat the 'database' as the
74
- # host name, and ignore the DBI::DBRC#dsn and DBI::DBRC#driver methods.
75
- #
76
- # Examples:
77
- #
78
- # # Find the first match for 'some_database'
79
- # DBI::DBRC.new('some_database')
80
- #
81
- # # Find the first match for 'foo_user@some_database'
82
- # DBI::DBRC.new('some_database', 'foo_user')
83
- #
84
- # # Find the first match for 'foo_user@some_database' under /usr/local
85
- # DBI::DBRC.new('some_database', 'foo_usr', '/usr/local')
86
- #
87
- def initialize(database, user=nil, dbrc_dir=nil)
88
- if dbrc_dir.nil?
89
- if Config::CONFIG['host_os'].match('mswin')
90
- home = ENV['USERPROFILE'] || ENV['HOME']
91
- file = nil
92
-
93
- if home
94
- file = File.join(home, '.dbrc')
95
- else
96
- file = File.join(File.basename(Dir::APPDATA), '.dbrc')
97
- end
98
-
99
- @dbrc_file = file
100
- else
101
- @dbrc_file = File.join(
102
- Sys::Admin.get_user(Process.uid).dir,
103
- '.dbrc'
104
- )
105
- end
106
- else
107
- @dbrc_file = File.join(dbrc_dir, '.dbrc')
108
- end
109
-
110
- @dbrc_dir = dbrc_dir
111
- @database = database
112
- @user = user
113
- encrypted = false # Win32 only
114
-
115
- @driver = nil
116
- @interval = nil
117
- @timeout = nil
118
- @maximum_reconnects = nil
119
-
120
- check_file()
121
-
122
- # If on Win32 and the file is encrypted, decrypt it.
123
- if Config::CONFIG['host_os'].match("mswin") && File.encrypted?(@dbrc_file)
124
- encrypted = true
125
- File.decrypt(@dbrc_file)
126
- end
127
-
128
- parse_dbrc_config_file()
129
- validate_data()
130
- convert_numeric_strings()
131
- create_dsn_string()
132
-
133
- # If on Win32 and the file was encrypted, re-encrypt it
134
- if Config::CONFIG['host_os'].match("mswin") && encrypted
135
- File.encrypt(@dbrc_file)
136
- end
137
- end
138
-
139
- private
140
-
141
- # Ensure that the user/password has been set
142
- def validate_data
143
- unless @user
144
- raise Error, "no user found associated with #{@database}"
145
- end
146
-
147
- unless @password
148
- raise Error, "password not defined for #{@user}@#{@database}"
149
- end
150
- end
151
-
152
- # Converts strings that should be numbers into actual numbers
153
- def convert_numeric_strings
154
- @interval = @interval.to_i if @interval
155
- @timeout = @timeout.to_i if @timeout
156
- @maximum_reconnects = @maximum_reconnects.to_i if @maximum_reconnects
157
- end
158
-
159
- # Create the dsn string if the driver is defined
160
- def create_dsn_string
161
- @dsn = "dbi:#{@driver}:#{@database}" if @driver
162
- end
163
-
164
- # Check ownership and permissions
165
- def check_file(file=@dbrc_file)
166
- File.open(file){ |f|
167
-
168
- # Permissions must be set to 600 or better on Unix systems.
169
- # Must be hidden on Win32 systems.
170
- if Config::CONFIG['host_os'].match("mswin")
171
- unless File.hidden?(file)
172
- raise Error, "The .dbrc file must be hidden"
173
- end
174
- else
175
- unless (f.stat.mode & 077) == 0
176
- raise Error, "Bad .dbrc file permissions"
177
- end
178
- end
179
-
180
- # Only the owner may use it
181
- unless f.stat.owned?
182
- raise Error, "Not owner of .dbrc file"
183
- end
184
- }
185
- end
186
-
187
- # Parse the text out of the .dbrc file. This is the only method you
188
- # need to redefine if writing your own config handler.
189
- def parse_dbrc_config_file(file=@dbrc_file)
190
- IO.foreach(file){ |line|
191
- next if line =~ /^#/ # Ignore comments
192
- db, user, pwd, driver, timeout, max, interval = line.split
193
-
194
- next unless @database == db
195
-
196
- if @user
197
- next unless @user == user
198
- end
199
-
200
- @user = user
201
- @password = pwd
202
- @driver = driver
203
- @timeout = timeout
204
- @maximum_reconnects = max
205
- @interval = interval
206
- return
207
- }
208
-
209
- # If we reach here it means the database and/or user wasn't found
210
- if @user
211
- err = "no record found for #{@user}@#{@database}"
212
- else
213
- err = "no record found for #{@database}"
214
- end
215
-
216
- raise Error, err
217
- end
218
-
219
- alias_method(:db, :database)
220
- alias_method(:db=, :database=)
221
- alias_method(:passwd, :password)
222
- alias_method(:passwd=, :password=)
223
- alias_method(:max_reconn, :maximum_reconnects)
224
- alias_method(:max_reconn=, :maximum_reconnects=)
225
- alias_method(:time_out, :timeout)
226
- alias_method(:time_out=, :timeout=)
227
- alias_method(:host, :database)
228
- end
229
-
230
- # A subclass of DBRC designed to handle .dbrc files in XML format. The
231
- # public methods of this class are identical to DBRC.
232
- class XML < DBRC
233
- require "rexml/document"
234
- include REXML
235
- private
236
- def parse_dbrc_config_file(file=@dbrc_file)
237
- doc = Document.new(File.new(file))
238
- fields = %w/user password driver interval timeout maximum_reconnects/
239
- doc.elements.each("/dbrc/database"){ |element|
240
- next unless element.attributes["name"] == database
241
- if @user
242
- next unless element.elements["user"].text == @user
243
- end
244
- fields.each{ |field|
245
- val = element.elements[field]
246
- unless val.nil?
247
- send("#{field}=",val.text)
248
- end
249
- }
250
- return
251
- }
252
- # If we reach here it means the database and/or user wasn't found
253
- raise Error, "No record found for #{@user}@#{@database}"
254
- end
255
- end
256
-
257
- # A subclass of DBRC designed to handle .dbrc files in YAML format. The
258
- # public methods of this class are identical to DBRC.
259
- class YML < DBRC
260
- require "yaml"
261
- private
262
- def parse_dbrc_config_file(file=@dbrc_file)
263
- config = YAML.load(File.open(file))
264
- config.each{ |hash|
265
- hash.each{ |db,info|
266
- next unless db == @database
267
- if @user
268
- next unless @user == info["user"]
269
- end
270
- @user = info["user"]
271
- @password = info["password"]
272
- @driver = info["driver"]
273
- @interval = info["interval"]
274
- @timeout = info["timeout"]
275
- @maximum_reconnects = info["max_reconn"]
276
- return
277
- }
278
- }
279
- # If we reach this point, it means the database wasn't found
280
- raise Error, "No entry found for #{@user}@#{@database}"
281
- end
282
- end
283
- end
1
+ require 'rbconfig'
2
+
3
+ if Config::CONFIG['host_os'].match('mswin')
4
+ require 'win32/file'
5
+ require 'win32/dir'
6
+ end
7
+
8
+ require 'sys/admin'
9
+
10
+ # The DBI module serves as a namespace only.
11
+ module DBI
12
+
13
+ # The DBRC class encapsulates a database resource config file.
14
+ class DBRC
15
+
16
+ # This error is raised if anything fails trying to read the config file.
17
+ # the error that is raised.
18
+ class Error < StandardError; end
19
+
20
+ # The version of this library
21
+ VERSION = '1.1.4'
22
+
23
+ # The database or host to be connected to.
24
+ attr_accessor :database
25
+
26
+ # The user name used for the database or host connection.
27
+ attr_accessor :user
28
+
29
+ # The password associated with the database or host.
30
+ attr_accessor :password
31
+
32
+ # The driver associated with the database. This is used to internally to
33
+ # construct the DSN.
34
+ attr_accessor :driver
35
+
36
+ # Data source name, e.g. "dbi:OCI8:your_database".
37
+ attr_accessor :dsn
38
+
39
+ # The maximum number of reconnects a program should make before
40
+ # giving up.
41
+ attr_accessor :maximum_reconnects
42
+
43
+ # The timeout, in seconds, for each connection attempt.
44
+ attr_accessor :timeout
45
+
46
+ # The interval, in seconds, between each connection attempt.
47
+ attr_accessor :interval
48
+
49
+ # The directory where the .dbrc file is stored.
50
+ attr_accessor :dbrc_dir
51
+
52
+ # The full path to the .dbrc file.
53
+ attr_accessor :dbrc_file
54
+
55
+ # Returns a new DBI::DBRC object. The contents of the object depend on
56
+ # the arguments passed to the constructor. If only a database name is
57
+ # passed, then the first entry found in the .dbrc file that matches that
58
+ # database is parsed. If a user name is also included, then the first
59
+ # entry that matches both the database and user name is parsed.
60
+ #
61
+ # If a directory is passed as the third argument, then DBRC will look
62
+ # in that directory, instead of the default directory, for the .dbrc
63
+ # file.
64
+ #
65
+ # If an entry cannot be found for the database, or database plus user
66
+ # combination, then a Error is raised. If the .dbrc file cannot
67
+ # be found, or is setup improperly with regards to permissions or
68
+ # properties, a DBI::DBRC::Error is raised.
69
+ #
70
+ # See the README for the rules regarding .dbrc files and permissions.
71
+ #
72
+ # Note that this library can also be used as a general password
73
+ # storage mechanism. In that case simply treat the 'database' as the
74
+ # host name, and ignore the DBI::DBRC#dsn and DBI::DBRC#driver methods.
75
+ #
76
+ # Examples:
77
+ #
78
+ # # Find the first match for 'some_database'
79
+ # DBI::DBRC.new('some_database')
80
+ #
81
+ # # Find the first match for 'foo_user@some_database'
82
+ # DBI::DBRC.new('some_database', 'foo_user')
83
+ #
84
+ # # Find the first match for 'foo_user@some_database' under /usr/local
85
+ # DBI::DBRC.new('some_database', 'foo_usr', '/usr/local')
86
+ #
87
+ def initialize(database, user=nil, dbrc_dir=nil)
88
+ if dbrc_dir.nil?
89
+ if Config::CONFIG['host_os'].match('mswin')
90
+ home = ENV['USERPROFILE'] || ENV['HOME']
91
+ file = nil
92
+
93
+ if home
94
+ file = File.join(home, '.dbrc')
95
+ else
96
+ file = File.join(File.basename(Dir::APPDATA), '.dbrc')
97
+ end
98
+
99
+ @dbrc_file = file
100
+ else
101
+ @dbrc_file = File.join(
102
+ Sys::Admin.get_user(Process.uid).dir,
103
+ '.dbrc'
104
+ )
105
+ end
106
+ else
107
+ @dbrc_file = File.join(dbrc_dir, '.dbrc')
108
+ end
109
+
110
+ @dbrc_dir = dbrc_dir
111
+ @database = database
112
+ @user = user
113
+ encrypted = false # Win32 only
114
+
115
+ @driver = nil
116
+ @interval = nil
117
+ @timeout = nil
118
+ @maximum_reconnects = nil
119
+
120
+ check_file()
121
+
122
+ # If on Win32 and the file is encrypted, decrypt it.
123
+ if Config::CONFIG['host_os'].match("mswin") && File.encrypted?(@dbrc_file)
124
+ encrypted = true
125
+ File.decrypt(@dbrc_file)
126
+ end
127
+
128
+ parse_dbrc_config_file()
129
+ validate_data()
130
+ convert_numeric_strings()
131
+ create_dsn_string()
132
+
133
+ # If on Win32 and the file was encrypted, re-encrypt it
134
+ if Config::CONFIG['host_os'].match("mswin") && encrypted
135
+ File.encrypt(@dbrc_file)
136
+ end
137
+ end
138
+
139
+ # Inspection of the DBI::DBRC object. This is identical to the standard
140
+ # Ruby Object#inspect, except that the password field is filtered.
141
+ #
142
+ def inspect
143
+ str = instance_variables.map{ |iv|
144
+ if iv == '@password'
145
+ "#{iv}=[FILTERED]"
146
+ else
147
+ "#{iv}=#{instance_variable_get(iv).inspect}"
148
+ end
149
+ }.join(', ')
150
+
151
+ "#<#{self.class}:0x#{(self.object_id*2).to_s(16)} " << str << ">"
152
+ end
153
+
154
+ private
155
+
156
+ # Ensure that the user/password has been set
157
+ def validate_data
158
+ unless @user
159
+ raise Error, "no user found associated with #{@database}"
160
+ end
161
+
162
+ unless @password
163
+ raise Error, "password not defined for #{@user}@#{@database}"
164
+ end
165
+ end
166
+
167
+ # Converts strings that should be numbers into actual numbers
168
+ def convert_numeric_strings
169
+ @interval = @interval.to_i if @interval
170
+ @timeout = @timeout.to_i if @timeout
171
+ @maximum_reconnects = @maximum_reconnects.to_i if @maximum_reconnects
172
+ end
173
+
174
+ # Create the dsn string if the driver is defined
175
+ def create_dsn_string
176
+ @dsn = "dbi:#{@driver}:#{@database}" if @driver
177
+ end
178
+
179
+ # Check ownership and permissions
180
+ def check_file(file=@dbrc_file)
181
+ File.open(file){ |f|
182
+
183
+ # Permissions must be set to 600 or better on Unix systems.
184
+ # Must be hidden on Win32 systems.
185
+ if Config::CONFIG['host_os'].match("mswin")
186
+ unless File.hidden?(file)
187
+ raise Error, "The .dbrc file must be hidden"
188
+ end
189
+ else
190
+ unless (f.stat.mode & 077) == 0
191
+ raise Error, "Bad .dbrc file permissions"
192
+ end
193
+ end
194
+
195
+ # Only the owner may use it
196
+ unless f.stat.owned?
197
+ raise Error, "Not owner of .dbrc file"
198
+ end
199
+ }
200
+ end
201
+
202
+ # Parse the text out of the .dbrc file. This is the only method you
203
+ # need to redefine if writing your own config handler.
204
+ def parse_dbrc_config_file(file=@dbrc_file)
205
+ IO.foreach(file){ |line|
206
+ next if line =~ /^#/ # Ignore comments
207
+ db, user, pwd, driver, timeout, max, interval = line.split
208
+
209
+ next unless @database == db
210
+
211
+ if @user
212
+ next unless @user == user
213
+ end
214
+
215
+ @user = user
216
+ @password = pwd
217
+ @driver = driver
218
+ @timeout = timeout
219
+ @maximum_reconnects = max
220
+ @interval = interval
221
+ return
222
+ }
223
+
224
+ # If we reach here it means the database and/or user wasn't found
225
+ if @user
226
+ err = "no record found for #{@user}@#{@database}"
227
+ else
228
+ err = "no record found for #{@database}"
229
+ end
230
+
231
+ raise Error, err
232
+ end
233
+
234
+ alias_method(:db, :database)
235
+ alias_method(:db=, :database=)
236
+ alias_method(:passwd, :password)
237
+ alias_method(:passwd=, :password=)
238
+ alias_method(:max_reconn, :maximum_reconnects)
239
+ alias_method(:max_reconn=, :maximum_reconnects=)
240
+ alias_method(:time_out, :timeout)
241
+ alias_method(:time_out=, :timeout=)
242
+ alias_method(:host, :database)
243
+ end
244
+
245
+ # A subclass of DBRC designed to handle .dbrc files in XML format. The
246
+ # public methods of this class are identical to DBRC.
247
+ class XML < DBRC
248
+ require "rexml/document"
249
+ include REXML
250
+ private
251
+ def parse_dbrc_config_file(file=@dbrc_file)
252
+ doc = Document.new(File.new(file))
253
+ fields = %w/user password driver interval timeout maximum_reconnects/
254
+ doc.elements.each("/dbrc/database"){ |element|
255
+ next unless element.attributes["name"] == database
256
+ if @user
257
+ next unless element.elements["user"].text == @user
258
+ end
259
+ fields.each{ |field|
260
+ val = element.elements[field]
261
+ unless val.nil?
262
+ send("#{field}=",val.text)
263
+ end
264
+ }
265
+ return
266
+ }
267
+ # If we reach here it means the database and/or user wasn't found
268
+ raise Error, "No record found for #{@user}@#{@database}"
269
+ end
270
+ end
271
+
272
+ # A subclass of DBRC designed to handle .dbrc files in YAML format. The
273
+ # public methods of this class are identical to DBRC.
274
+ class YML < DBRC
275
+ require "yaml"
276
+ private
277
+ def parse_dbrc_config_file(file=@dbrc_file)
278
+ config = YAML.load(File.open(file))
279
+ config.each{ |hash|
280
+ hash.each{ |db,info|
281
+ next unless db == @database
282
+ if @user
283
+ next unless @user == info["user"]
284
+ end
285
+ @user = info["user"]
286
+ @password = info["password"]
287
+ @driver = info["driver"]
288
+ @interval = info["interval"]
289
+ @timeout = info["timeout"]
290
+ @maximum_reconnects = info["max_reconn"]
291
+ return
292
+ }
293
+ }
294
+ # If we reach this point, it means the database wasn't found
295
+ raise Error, "No entry found for #{@user}@#{@database}"
296
+ end
297
+ end
298
+ end