| Module | DBI::Utils |
| In: |
lib/dbi/utils.rb
lib/dbi/utils/xmlformatter.rb lib/dbi/utils/tableformatter.rb |
Utility classes and methods for use by both DBDs and consumers.
Given a block, returns the execution time for the block.
# File lib/dbi/utils.rb, line 13
13: def self.measure
14: start = ::Time.now
15: yield
16: ::Time.now - start
17: end
parse a string of the form "database=xxx;key=val;…" or database:host and return hash of key/value pairs
Used in DBI.connect and offspring.
# File lib/dbi/utils.rb, line 25
25: def self.parse_params(str)
26: # improved by John Gorman <jgorman@webbysoft.com>
27: params = str.split(";")
28: hash = {}
29: params.each do |param|
30: key, val = param.split("=")
31: hash[key] = val if key and val
32: end
33: if hash.empty?
34: database, host = str.split(":")
35: hash['database'] = database if database
36: hash['host'] = host if host
37: end
38: hash
39: end