Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Remove EnhancedQueryAnalyzer.logging = <bool> & EnhancedQueryAnalyzer…

….logging. Use log_if { false } if you'd like to turn it off
  • Loading branch information...
commit 1d0e88745091d6c8b82691a8e42a18d472596664 1 parent 52a8ac5
Scott Taylor authored
8 lib/enhanced_query_analyzer/logging.rb
... ... @@ -1,16 +1,11 @@
1 1 module EnhancedQueryAnalyzer
2 2 module Logging
3   - attr_writer :logging, :explain_logging
  3 + attr_writer :explain_logging
4 4
5 5 def explain_logging
6 6 @explain_logging ||= false
7 7 end
8 8
9   - def logging
10   - @logging = true if @logging.equal? nil
11   - @logging
12   - end
13   -
14 9 def slow_query_time
15 10 @slow_query_time ||= nil
16 11 end
@@ -30,7 +25,6 @@ def log_if(&block)
30 25 end
31 26
32 27 def reset!
33   - @logging = nil
34 28 @explain_logging = nil
35 29 @logging_conditions = lambda { |_, _| true }
36 30 end
2  lib/enhanced_query_analyzer/select_proxy.rb
... ... @@ -1,7 +1,7 @@
1 1 module EnhancedQueryAnalyzer
2 2 module SelectProxy
3 3 def select(adapter, sql, name)
4   - SelectRunner.new(adapter, logging, explain_logging, logging_conditions).select(sql, name)
  4 + SelectRunner.new(adapter, explain_logging, logging_conditions).select(sql, name)
5 5 end
6 6 end
7 7 end
11 lib/enhanced_query_analyzer/select_runner.rb
... ... @@ -1,18 +1,11 @@
1 1 module EnhancedQueryAnalyzer
2 2 class SelectRunner
3   - def initialize(adapter, logging_on, explain_logging_on, log_conditions)
  3 + def initialize(adapter, explain_logging_on, log_conditions)
4 4 @adapter = adapter
5   - @logging_on = logging_on
6 5 @explain_logging_on = explain_logging_on
7 6 @log_conditions = log_conditions
8 7 end
9 8
10   - attr_reader :logging_on
11   -
12   - def logging_on?
13   - @logging_on ? true : false
14   - end
15   -
16 9 def explain_logging_on?
17 10 @explain_logging_on ? true : false
18 11 end
@@ -49,7 +42,7 @@ def explain(sql)
49 42 end
50 43
51 44 def log_query?(sql, time)
52   - logging_on? && table_for_selection?(sql) && @log_conditions.call(sql, time)
  45 + table_for_selection?(sql) && @log_conditions.call(sql, time)
53 46 end
54 47
55 48 def table_for_selection?(sql)
2  spec/enhanced_query_analyzer/logging_spec.rb
@@ -41,7 +41,7 @@ def read_fixture(file)
41 41 end
42 42
43 43 it "should not create an entry if logging is turned off" do
44   - EnhancedQueryAnalyzer.logging = false
  44 + EnhancedQueryAnalyzer.log_if { |query, time| false }
45 45 lambda {
46 46 User.find_by_sql <<-SQL
47 47 SELECT * FROM users
14 spec/enhanced_query_analyzer/query_analyzer_spec.rb
@@ -5,20 +5,6 @@
5 5 EnhancedQueryAnalyzer.reset!
6 6 end
7 7
8   - it "should have logging on by default" do
9   - EnhancedQueryAnalyzer.logging.should be_true
10   - end
11   -
12   - it "should be able to set logging to false" do
13   - EnhancedQueryAnalyzer.logging = false
14   - EnhancedQueryAnalyzer.logging.should be_false
15   - end
16   -
17   - it "should be able to reset the logs" do
18   - EnhancedQueryAnalyzer.reset!
19   - EnhancedQueryAnalyzer.logging.should be_true
20   - end
21   -
22 8 it "should have explain logging off by default" do
23 9 EnhancedQueryAnalyzer.explain_logging.should be_false
24 10 end

0 comments on commit 1d0e887

Please sign in to comment.
Something went wrong with that request. Please try again.