File: utils.rb

package info (click to toggle)
libdbi-ruby 0.4.3-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 472 kB
  • ctags: 619
  • sloc: ruby: 4,583; makefile: 62; perl: 12
file content (60 lines) | stat: -rw-r--r-- 1,632 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#
# $Id: utils.rb,v 1.5 2006/01/29 06:14:19 djberg96 Exp $
#

module DBI
    #
    # Utility classes and methods for use by both DBDs and consumers.
    #
    module Utils
        #
        # Given a block, returns the execution time for the block.
        #
        def self.measure
            start = ::Time.now
            yield
            ::Time.now - start
        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.
        #
        def self.parse_params(str)
            # improved by John Gorman <jgorman@webbysoft.com>
            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
    end # module Utils
end # module DBI

#
# Type converter.
#
# FIXME this really needs to go into DBI::TypeUtil or similar
module DBI::Utils::ConvParam
    #
    # Wrapper to convert arrays of bound objects via DBI::TypeUtil#convert.
    #
    def self.conv_param(driver_name, *params)
        params.collect { |param| DBI::TypeUtil.convert(driver_name, param) }
    end
end

require 'dbi/utils/date'
require 'dbi/utils/time'
require 'dbi/utils/timestamp'
require 'dbi/utils/xmlformatter'
require 'dbi/utils/tableformatter'