sql_footprint 0.2.1 → 0.3.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: 1808864d64806786586f98122e3f3d0881c36a48
4
- data.tar.gz: c90cd6dd406e18a8e703b3524f548ebd5450953e
3
+ metadata.gz: 345372cb4105c987060e487d17b4dd6031ac0828
4
+ data.tar.gz: cd0d79b65ad986d3aae9629e9baf6ef2760364f3
5
5
  SHA512:
6
- metadata.gz: 82d008d6324252cec284f59b423eb5b3db9741a2b36e1b718fb74fec66b15d6b9d66c7d8ad446fb7a628d808b1446ad40a0251995a6bc8a9fa9bc4719ede07fa
7
- data.tar.gz: b910dcdf01af5715bab1a0b5149c6b8ef52bafbf75798e7c32b45e7cca08a4a2d097d58f19f5c9939b54fc73832b9765c8ec794808c76e07c89cd3b15ea6d836
6
+ metadata.gz: ec978a30dd1f59dfe9f199d3ff723fb0ae9064fc1d641fbb04e04bbfa269f914255bd152113b693bd3491af8b8449eb5402ca5321fea6210424835d1b32db93c
7
+ data.tar.gz: 078aab8ffc686233865ac57cd68f81c121d921c029fb3911c2c78750ce8ccb966d98855964637c368a1d5c35b3babbba58adf21b623f106455b79a9af57fc524
data/.travis.yml CHANGED
@@ -5,7 +5,11 @@ script:
5
5
  sudo: false
6
6
  rvm:
7
7
  - 1.9.3
8
- - 2.0
8
+ - 2.0.0
9
9
  - 2.1
10
10
  - 2.2
11
- - rbx-2
11
+ - 2.3.0
12
+ - rbx
13
+ matrix:
14
+ allow_failures:
15
+ - rvm: rbx
data/lib/sql_footprint.rb CHANGED
@@ -1,88 +1,64 @@
1
1
  require 'sql_footprint/version'
2
+ require 'set'
3
+ require 'active_support/notifications'
2
4
 
3
5
  module SqlFootprint
4
- def self.start
5
- @original_logger = ActiveRecord::Base.logger
6
- @logger = Logger.new
7
- ActiveRecord::Base.logger = @logger
6
+ ActiveSupport::Notifications.subscribe('sql.active_record') do |_, _, _, _, payload|
7
+ capture payload.fetch(:sql)
8
8
  end
9
9
 
10
- def self.stop
11
- ActiveRecord::Base.logger = @original_logger
12
- File.open('footprint.sql', 'w') do |f|
13
- @logger.logs.each do |log|
14
- f.puts log
15
- end
16
- end
17
- end
18
-
19
- def self.exclude
20
- ActiveRecord::Base.logger = @original_logger
21
- yield
22
- ensure
23
- ActiveRecord::Base.logger = @logger
24
- end
25
-
26
- class Logger
27
- def initialize
28
- @logs = []
10
+ class << self
11
+ def start
12
+ @capture = true
13
+ @lines = Set.new
29
14
  end
30
15
 
31
- attr_reader :logs
32
-
33
- def error param
34
- raise param
35
- end
36
-
37
- def debug text
38
- if sql? text
39
- sql = format_sql(text)
40
- logs << sql unless logs.include?(sql)
41
- logs.sort!
16
+ def stop
17
+ @capture = false
18
+ File.open('footprint.sql', 'w') do |f|
19
+ lines.each do |line|
20
+ f.puts line
21
+ end
42
22
  end
43
23
  end
44
24
 
45
- def debug?
46
- true
25
+ def exclude
26
+ @capture = false
27
+ yield
28
+ ensure
29
+ @capture = true
47
30
  end
48
31
 
49
- private
50
-
51
- SQL_REGEXS = [/SQL/, /Load\s\(/, /Exists\s\(/].map(&:freeze).freeze
52
-
53
- def sql? text
54
- SQL_REGEXS.any? { |regex| regex.match(text) }
32
+ def lines
33
+ @lines.sort
55
34
  end
56
35
 
57
- def format_sql text
58
- strip_values(text).split("\e\[0m")
59
- .select { |t| !t.include?('SQL') }
60
- .find { |t| !/Load\s\(/.match(t) }
61
- .gsub(/\e\[1m/, '')
62
- .strip
36
+ def capture sql
37
+ return unless @capture
38
+ @lines << strip_values(sql)
63
39
  end
64
40
 
65
- def strip_values text
66
- text = text.gsub(/\[\[.*\]\]/, '')
67
- text = strip_string_values(text)
68
- text = strip_integer_values(text)
69
- strip_in_clause_values(text)
41
+ def strip_values sql
42
+ sql = sql.gsub(/\[\[.*\]\]/, '')
43
+ sql = strip_string_values(sql)
44
+ sql = strip_integer_values(sql)
45
+ strip_in_clause_values(sql)
70
46
  end
71
47
 
72
- def strip_in_clause_values text
73
- text.gsub(/\sIN\s\((.*)\)/) do |_match|
48
+ def strip_in_clause_values sql
49
+ sql.gsub(/\sIN\s\((.*)\)/) do |_match|
74
50
  ' IN (values-redacted)'
75
51
  end
76
52
  end
77
53
 
78
- def strip_integer_values text
79
- text.gsub(/\s\=\s([0-9]+)/) do |_match|
54
+ def strip_integer_values sql
55
+ sql.gsub(/\s\=\s([0-9]+)/) do |_match|
80
56
  ' = number-redacted'
81
57
  end
82
58
  end
83
59
 
84
- def strip_string_values text
85
- text.gsub(/\s\=\s\'(.*)\'/) do |_match|
60
+ def strip_string_values sql
61
+ sql.gsub(/\s\=\s\'(.*)\'/) do |_match|
86
62
  " = 'value-redacted'"
87
63
  end
88
64
  end
@@ -1,3 +1,3 @@
1
1
  module SqlFootprint
2
- VERSION = '0.2.1'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ['Brandon Joyce']
10
10
  spec.email = ['bjoyce@covermymeds.com']
11
11
 
12
- spec.summary = 'Keeps your DB guy happy.'
12
+ spec.summary = 'Keeps your DBA happy.'
13
13
  spec.description = 'Check your footprint file into source control'
14
14
  spec.homepage = 'https://github.com/covermymeds/sql_footprint'
15
15
 
@@ -20,10 +20,12 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ['lib']
22
22
 
23
+ spec.add_dependency 'activerecord', '~> 4.0'
24
+ spec.add_dependency 'activesupport', '~> 4.0'
25
+
23
26
  spec.add_development_dependency 'bundler', '~> 1.7'
24
27
  spec.add_development_dependency 'rake', '~> 10.0'
25
28
  spec.add_development_dependency 'rspec'
26
- spec.add_development_dependency 'activerecord', '~> 4.0.0'
27
29
  spec.add_development_dependency 'pry'
28
30
  spec.add_development_dependency 'sqlite3'
29
31
  spec.add_development_dependency 'rubocop', '~> 0.37.0'
metadata CHANGED
@@ -1,125 +1,139 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sql_footprint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Joyce
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-01 00:00:00.000000000 Z
11
+ date: 2016-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: bundler
15
43
  requirement: !ruby/object:Gem::Requirement
16
44
  requirements:
17
- - - ~>
45
+ - - "~>"
18
46
  - !ruby/object:Gem::Version
19
47
  version: '1.7'
20
48
  type: :development
21
49
  prerelease: false
22
50
  version_requirements: !ruby/object:Gem::Requirement
23
51
  requirements:
24
- - - ~>
52
+ - - "~>"
25
53
  - !ruby/object:Gem::Version
26
54
  version: '1.7'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: rake
29
57
  requirement: !ruby/object:Gem::Requirement
30
58
  requirements:
31
- - - ~>
59
+ - - "~>"
32
60
  - !ruby/object:Gem::Version
33
61
  version: '10.0'
34
62
  type: :development
35
63
  prerelease: false
36
64
  version_requirements: !ruby/object:Gem::Requirement
37
65
  requirements:
38
- - - ~>
66
+ - - "~>"
39
67
  - !ruby/object:Gem::Version
40
68
  version: '10.0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: rspec
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
- - - '>='
73
+ - - ">="
46
74
  - !ruby/object:Gem::Version
47
75
  version: '0'
48
76
  type: :development
49
77
  prerelease: false
50
78
  version_requirements: !ruby/object:Gem::Requirement
51
79
  requirements:
52
- - - '>='
80
+ - - ">="
53
81
  - !ruby/object:Gem::Version
54
82
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: activerecord
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: 4.0.0
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ~>
67
- - !ruby/object:Gem::Version
68
- version: 4.0.0
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: pry
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - '>='
87
+ - - ">="
74
88
  - !ruby/object:Gem::Version
75
89
  version: '0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - '>='
94
+ - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: sqlite3
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
- - - '>='
101
+ - - ">="
88
102
  - !ruby/object:Gem::Version
89
103
  version: '0'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - '>='
108
+ - - ">="
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rubocop
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
- - - ~>
115
+ - - "~>"
102
116
  - !ruby/object:Gem::Version
103
117
  version: 0.37.0
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
- - - ~>
122
+ - - "~>"
109
123
  - !ruby/object:Gem::Version
110
124
  version: 0.37.0
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: rubocop-rspec
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
- - - '>='
129
+ - - ">="
116
130
  - !ruby/object:Gem::Version
117
131
  version: '0'
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
- - - '>='
136
+ - - ">="
123
137
  - !ruby/object:Gem::Version
124
138
  version: '0'
125
139
  description: Check your footprint file into source control
@@ -129,10 +143,10 @@ executables: []
129
143
  extensions: []
130
144
  extra_rdoc_files: []
131
145
  files:
132
- - .gitignore
133
- - .rspec
134
- - .rubocop.yml
135
- - .travis.yml
146
+ - ".gitignore"
147
+ - ".rspec"
148
+ - ".rubocop.yml"
149
+ - ".travis.yml"
136
150
  - Gemfile
137
151
  - README.md
138
152
  - Rakefile
@@ -150,18 +164,19 @@ require_paths:
150
164
  - lib
151
165
  required_ruby_version: !ruby/object:Gem::Requirement
152
166
  requirements:
153
- - - '>='
167
+ - - ">="
154
168
  - !ruby/object:Gem::Version
155
169
  version: '0'
156
170
  required_rubygems_version: !ruby/object:Gem::Requirement
157
171
  requirements:
158
- - - '>='
172
+ - - ">="
159
173
  - !ruby/object:Gem::Version
160
174
  version: '0'
161
175
  requirements: []
162
176
  rubyforge_project:
163
- rubygems_version: 2.5.1
177
+ rubygems_version: 2.4.8
164
178
  signing_key:
165
179
  specification_version: 4
166
- summary: Keeps your DB guy happy.
180
+ summary: Keeps your DBA happy.
167
181
  test_files: []
182
+ has_rdoc: