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 CHANGED
@@ -53,12 +53,4 @@ module RDO
53
53
 
54
54
  alias_method :open, :connect
55
55
  end
56
-
57
- # A suitable NULL device for writing nothing
58
- DEV_NULL =
59
- if defined? IO::NULL
60
- IO::NULL
61
- else
62
- ENV["OS"] =~ /Windows/ ? "NUL" : "/dev/null"
63
- end
64
56
  end
@@ -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 formatter
14
- @formatter ||=
15
- Proc.new do |severity, time, prog, msg|
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
@@ -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
- @logger = @options.fetch(:logger, null_logger)
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 null_logger
190
- Logger.new(RDO::DEV_NULL).tap{|l| l.level = Logger::UNKNOWN}
190
+ def default_logger
191
+ ColoredLogger.new(STDOUT).tap{|l| l.level = Logger::UNKNOWN}
191
192
  end
192
193
  end
193
194
  end
@@ -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
  #
@@ -6,5 +6,5 @@
6
6
  ##
7
7
 
8
8
  module RDO
9
- VERSION = "0.1.1"
9
+ VERSION = "0.1.2"
10
10
  end
@@ -2,7 +2,7 @@ require "spec_helper"
2
2
  require "logger"
3
3
 
4
4
  describe RDO::Statement do
5
- let(:logger) { Logger.new(RDO::DEV_NULL) }
5
+ let(:logger) { Logger.new(RDO::Util::DEV_NULL) }
6
6
  let(:executor) { double(:executor) }
7
7
  let(:stmt) { RDO::Statement.new(executor, logger) }
8
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: