sql_tagger 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b7df0d78b3a94e79c9a8dbe4004b6b42a6b2ca2
4
- data.tar.gz: 96f28433e8752ffd4c3ffd413ffdc8aa7078967b
3
+ metadata.gz: 6ba8b3d9228f6bc5892be02416589662b169071b
4
+ data.tar.gz: 8a27f05d376164274050b2ba2a773841cbf2b04d
5
5
  SHA512:
6
- metadata.gz: b1505eab9c0b0f24dc4fc324b9d360d1e52810e957252c2eef814ba6996c384ce72b78fe173057a62a5d3d15603c08a3c43884979378e6d0f6d81df9f2673e93
7
- data.tar.gz: b0d48bd55f0f659f5d71e494808dff705079b1726495a3f8ad22914c90e69197e880a2aa92d245f53a9d8875fbc7b680741989bc367d4c382af31d6e514b8717
6
+ metadata.gz: a14276e6e2746a2b685bc8d8ecfcf7096f12fbc6361d75663dba32d4dd790e448eaba61fbdbb73562435867caa4567be4e8193e32c3c8095c2a0632c11dd1a6c
7
+ data.tar.gz: 0a622ae346fc79fd05e147859e9dc4b4231f2cf7b986c888973dc84b83b847461f252f556a5f1241aa8e13d44023ed4200583a1e33d2333f282cd12f4d210ec5
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.1.0
@@ -7,6 +7,10 @@ class SqlTagger
7
7
  File.join(File.dirname(__FILE__), '..', 'VERSION')
8
8
  ).chomp.freeze
9
9
 
10
+ # @return [String, #call] a string or a proc which resolves to a string
11
+ # to prefix the call trace tag
12
+ attr_accessor :custom_tag_prefix
13
+
10
14
  # @return [Regexp]
11
15
  # regular expression used to match stack strings we should skip (usually
12
16
  # because such stack strings aren't specific enough, like stack strings
@@ -33,7 +37,7 @@ class SqlTagger
33
37
  caller(2).each do |string|
34
38
  next if @exclusion_cache.member?(string)
35
39
  if string !~ @exclusion_pattern
36
- return "/* #{string} */ #{sql}"
40
+ return "/* #{custom_tag_prefix_string} #{string} */ #{sql}"
37
41
  else
38
42
  @exclusion_cache.add(string)
39
43
  end
@@ -101,4 +105,17 @@ class SqlTagger
101
105
  end
102
106
  end
103
107
  end
108
+
109
+ private
110
+
111
+ # Returns a freshly resolved custom tag prefix string
112
+ #
113
+ # @return [String] string to prefix the call trace tag
114
+ def custom_tag_prefix_string
115
+ if @custom_tag_prefix.respond_to?(:call)
116
+ @custom_tag_prefix.call
117
+ else
118
+ @custom_tag_prefix
119
+ end
120
+ end
104
121
  end
@@ -21,7 +21,7 @@ RSpec.describe SqlTagger do
21
21
  end
22
22
 
23
23
  it 'skips stack strings that match @exclusion_pattern' do
24
- expect(sql_tagger.tag(sql)).to eq("/* #{valid_stack_string} */ #{sql}")
24
+ expect(sql_tagger.tag(sql)).to eq("/* #{valid_stack_string} */ #{sql}")
25
25
  end
26
26
 
27
27
  it 'returns the 1st stack string that does not match @exclusion_pattern' do
@@ -29,7 +29,7 @@ RSpec.describe SqlTagger do
29
29
  '/home/app/myapp/lib/document.rb:788',
30
30
  '/home/app/myapp/runner.rb:29'
31
31
  )
32
- expect(sql_tagger.tag(sql)).to eq("/* #{valid_stack_string} */ #{sql}")
32
+ expect(sql_tagger.tag(sql)).to eq("/* #{valid_stack_string} */ #{sql}")
33
33
  end
34
34
 
35
35
  it 'adds skipped stack strings into @exclusion_cache' do
@@ -45,7 +45,26 @@ RSpec.describe SqlTagger do
45
45
  correct_string = '/home/myapp/i.rb:2890'
46
46
  caller_result.push(correct_string)
47
47
  sql_tagger.exclusion_cache.add(valid_stack_string)
48
- expect(sql_tagger.tag(sql)).to eq("/* #{correct_string} */ #{sql}")
48
+ expect(sql_tagger.tag(sql)).to eq("/* #{correct_string} */ #{sql}")
49
+ end
50
+
51
+ context 'when @custom_tag_prefix is set as a proc' do
52
+ it 'prefixes the tag with a freshly resolved @custom_tag_prefix proc' do
53
+ string_stack = ['a', 'b']
54
+ sql_tagger.custom_tag_prefix = proc { string_stack.pop }
55
+ expect(sql_tagger.tag(sql)).
56
+ to eq("/* b #{valid_stack_string} */ #{sql}")
57
+ expect(sql_tagger.tag(sql)).
58
+ to eq("/* a #{valid_stack_string} */ #{sql}")
59
+ end
60
+ end
61
+
62
+ context 'when @custom_tag_prefix is set as a string' do
63
+ it 'prefixes the tag with the set @custom_tag_prefix' do
64
+ sql_tagger.custom_tag_prefix = 'a'
65
+ expect(sql_tagger.tag(sql)).
66
+ to eq("/* a #{valid_stack_string} */ #{sql}")
67
+ end
49
68
  end
50
69
  end
51
70
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sql_tagger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toby Hsieh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-09 00:00:00.000000000 Z
11
+ date: 2016-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec