Module: DBI::Utils

Defined in:
lib/dbi/utils.rb,
lib/dbi/utils/xmlformatter.rb,
lib/dbi/utils/tableformatter.rb

Overview

Utility classes and methods for use by both DBDs and consumers.

Defined Under Namespace

Modules: ConvParam, TableFormatter, XMLFormatter

Class Method Summary collapse

Class Method Details

.measureObject

Given a block, returns the execution time for the block.



13
14
15
16
17
# File 'lib/dbi/utils.rb', line 13

def self.measure
    start = ::Time.now
    yield
    ::Time.now - start
end

.parse_params(str) ⇒ Object

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.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/dbi/utils.rb', line 25

def self.parse_params(str)
    # improved by John Gorman <[email protected]>
    params = str.split(";")
    hash = {}
    params.each do |param| 
        key, val = param.split("=") 
        hash[key] = val if key and val
    end 
    if hash.empty?
        database, host = str.split(":")
        hash['database'] = database if database
        hash['host']     = host if host   
    end
    hash 
end