rdo 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rdo.rb +0 -8
- data/lib/rdo/colored_logger.rb +16 -12
- data/lib/rdo/connection.rb +5 -4
- data/lib/rdo/util.rb +8 -0
- data/lib/rdo/version.rb +1 -1
- data/spec/rdo/statement_spec.rb +1 -1
- metadata +1 -1
data/lib/rdo.rb
CHANGED
data/lib/rdo/colored_logger.rb
CHANGED
@@ -10,22 +10,26 @@ require "logger"
|
|
10
10
|
module RDO
|
11
11
|
# A Logger that outputs using color to highlight errors etc.
|
12
12
|
class ColoredLogger < Logger
|
13
|
-
def
|
14
|
-
|
15
|
-
|
16
|
-
case severity
|
17
|
-
when "DEBUG"
|
18
|
-
format_sql(msg)
|
19
|
-
when "FATAL"
|
20
|
-
format_err(msg)
|
21
|
-
else
|
22
|
-
"%s ~ %s" % [severity, msg]
|
23
|
-
end + $/
|
24
|
-
end
|
13
|
+
def initialize(*args)
|
14
|
+
super
|
15
|
+
self.formatter = color_formatter
|
25
16
|
end
|
26
17
|
|
27
18
|
private
|
28
19
|
|
20
|
+
def color_formatter
|
21
|
+
Proc.new do |severity, time, prog, msg|
|
22
|
+
case severity
|
23
|
+
when "DEBUG"
|
24
|
+
format_sql(msg)
|
25
|
+
when "FATAL"
|
26
|
+
format_err(msg)
|
27
|
+
else
|
28
|
+
"%s ~ %s" % [severity, msg]
|
29
|
+
end + $/
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
29
33
|
def format_sql(sql)
|
30
34
|
"\033[35mSQL\033[0m \033[36m~\033[0m %s" % sql
|
31
35
|
end
|
data/lib/rdo/connection.rb
CHANGED
@@ -7,7 +7,6 @@
|
|
7
7
|
|
8
8
|
require "uri"
|
9
9
|
require "cgi"
|
10
|
-
require "logger"
|
11
10
|
require "forwardable"
|
12
11
|
|
13
12
|
module RDO
|
@@ -65,7 +64,9 @@ module RDO
|
|
65
64
|
# a Connection for the given options
|
66
65
|
def initialize(uri, options = {})
|
67
66
|
@options = normalize_options(uri).merge(normalize_options(options))
|
68
|
-
|
67
|
+
|
68
|
+
@logger = @options.fetch(:logger, default_logger)
|
69
|
+
@logger.level = @options[:log_level] if @options.key?(:log_level)
|
69
70
|
|
70
71
|
unless self.class.drivers.key?(@options[:driver])
|
71
72
|
raise RDO::Exception,
|
@@ -186,8 +187,8 @@ module RDO
|
|
186
187
|
str.nil? ? {} : Hash[CGI.parse(str).map{|k,v| [k, v.size == 1 ? v.first : v]}]
|
187
188
|
end
|
188
189
|
|
189
|
-
def
|
190
|
-
|
190
|
+
def default_logger
|
191
|
+
ColoredLogger.new(STDOUT).tap{|l| l.level = Logger::UNKNOWN}
|
191
192
|
end
|
192
193
|
end
|
193
194
|
end
|
data/lib/rdo/util.rb
CHANGED
@@ -14,6 +14,14 @@ module RDO
|
|
14
14
|
# Performing these operations in C would not be any cheaper, since the data
|
15
15
|
# must first be converted into Ruby types anyway.
|
16
16
|
module Util
|
17
|
+
# A suitable NULL device for writing nothing
|
18
|
+
DEV_NULL =
|
19
|
+
if defined? IO::NULL
|
20
|
+
IO::NULL
|
21
|
+
else
|
22
|
+
ENV["OS"] =~ /Windows/ ? "NUL" : "/dev/null"
|
23
|
+
end
|
24
|
+
|
17
25
|
class << self
|
18
26
|
# Convert a String to a Float, taking into account Infinity and NaN.
|
19
27
|
#
|
data/lib/rdo/version.rb
CHANGED
data/spec/rdo/statement_spec.rb
CHANGED