sql_tagger 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/lib/sql_tagger.rb CHANGED
@@ -10,7 +10,7 @@ class SqlTagger
10
10
  # regular expression used to match stack strings we should skip (usually
11
11
  # because such stack strings aren't specific enough, like stack strings
12
12
  # where the file belongs to a gem)
13
- attr_accessor :exclusion_pattern
13
+ attr_reader :exclusion_pattern
14
14
 
15
15
  # @return [Set] set that holds stack strings we skipped before
16
16
  attr_reader :exclusion_cache
@@ -42,6 +42,14 @@ class SqlTagger
42
42
  "/* SqlTagger#tag skipped the whole stack */ #{sql}"
43
43
  end
44
44
 
45
+ # Sets +@exclusion_pattern+.
46
+ #
47
+ # @param [Regexp] regexp regular expression to be used to skip stack strings
48
+ def exclusion_pattern=(regexp)
49
+ @exclusion_pattern = regexp
50
+ @exclusion_cache.clear
51
+ end
52
+
45
53
  @default = self.new
46
54
 
47
55
  class << self
@@ -55,6 +63,12 @@ class SqlTagger
55
63
  def self.included(base)
56
64
  base.send(:alias_method, :initialize_without_sql_tagger, :initialize)
57
65
  base.send(:alias_method, :initialize, :initialize_with_sql_tagger)
66
+
67
+ # This is for the odd case where a SQL gem/library is used before
68
+ # sql_tagger is required.
69
+ ObjectSpace.each_object(base) do |obj|
70
+ obj.sql_tagger ||= SqlTagger.default
71
+ end
58
72
  end
59
73
 
60
74
  # @return [SqlTagger] the SqlTagger used to tag queries for this instance
@@ -1,9 +1,12 @@
1
1
  require 'sql_tagger'
2
2
 
3
3
  describe SqlTagger do
4
+ before :each do
5
+ @sql_tagger = SqlTagger.new
6
+ end
7
+
4
8
  describe '#tag' do
5
9
  before :each do
6
- @sql_tagger = SqlTagger.new
7
10
  prefix = '/usr'
8
11
  @sql_tagger.exclusion_pattern = /^#{prefix}/
9
12
 
@@ -47,6 +50,19 @@ describe SqlTagger do
47
50
  end
48
51
  end
49
52
 
53
+ describe '#exclusion_pattern=' do
54
+ it 'sets @exclusion_pattern' do
55
+ @sql_tagger.exclusion_pattern = /regexp/
56
+ @sql_tagger.exclusion_pattern.should == /regexp/
57
+ end
58
+
59
+ it 'clears @exclusion_cache' do
60
+ @sql_tagger.exclusion_cache.merge(['/usr', '/opt'])
61
+ @sql_tagger.exclusion_pattern = /regexp/
62
+ @sql_tagger.exclusion_cache.should be_empty
63
+ end
64
+ end
65
+
50
66
  describe '.default' do
51
67
  it 'returns a functional SqlTagger' do
52
68
  SqlTagger.default.should be_a(SqlTagger)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sql_tagger
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Toby Hsieh
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-11 00:00:00 -07:00
18
+ date: 2012-05-16 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency