Module: DBI::Utils
- Defined in:
- lib/dbi/utils.rb
Defined Under Namespace
Modules: ConvParam, TableFormatter, XMLFormatter
Class Method Summary collapse
- .measure ⇒ Object
-
.parse_params(str) ⇒ Object
parse a string of the form “database=xxx;key=val;…” or database:host and return hash of key/value pairs.
Class Method Details
.measure ⇒ Object
198 199 200 201 202 |
# File 'lib/dbi/utils.rb', line 198 def Utils.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
improved by John Gorman <[email protected]>
209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/dbi/utils.rb', line 209 def Utils.parse_params(str) 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 |