sql_footprint 0.8.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/History.md +5 -0
- data/lib/sql_footprint/footprint_serializer.rb +13 -0
- data/lib/sql_footprint/sql_capturer.rb +33 -0
- data/lib/sql_footprint/version.rb +1 -1
- data/lib/sql_footprint.rb +12 -15
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 496830234a8ea90773d91b585d7ec937671b5712
|
4
|
+
data.tar.gz: 4f0ec6e6b1fb20d5b95eb78057ba883006c00d7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90e16e7c7ac1fae49f14d38c453cfe36324e9d3fdf6c2aadfdf9e829b343f3fbd13ec75c30d614d0f6f6c87064bdadfee811f60870155dd24688592723e58eda
|
7
|
+
data.tar.gz: 1a82424a427d0544dfcbb6d12eaacad5f0e5b0cdab79ec455be763905b70b2d6d8e1b54be3579f46221aed78b4d00fcee744fe1afba756bd2aacd57085df9b2a
|
data/.gitignore
CHANGED
data/History.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'sql_footprint/footprint_serializer'
|
2
|
+
|
3
|
+
module SqlFootprint
|
4
|
+
class SqlCapturer
|
5
|
+
attr_reader :statements, :database_name
|
6
|
+
|
7
|
+
def initialize database_name
|
8
|
+
@anonymizer = SqlAnonymizer.new
|
9
|
+
@filter = SqlFilter.new
|
10
|
+
@statements = SqlStatements.new
|
11
|
+
@database_name = database_name
|
12
|
+
end
|
13
|
+
|
14
|
+
def capture sql
|
15
|
+
return unless @filter.capture?(sql)
|
16
|
+
@statements.add @anonymizer.anonymize(sql)
|
17
|
+
end
|
18
|
+
|
19
|
+
def write
|
20
|
+
File.write filename, serialized_statements
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def serialized_statements
|
26
|
+
SqlFootprint::FootprintSerializer.new(statements).to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
def filename
|
30
|
+
"footprint.#{database_name.split('/').last}.sql"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/sql_footprint.rb
CHANGED
@@ -1,30 +1,32 @@
|
|
1
1
|
require 'sql_footprint/version'
|
2
2
|
require 'sql_footprint/sql_anonymizer'
|
3
|
+
require 'sql_footprint/sql_capturer'
|
3
4
|
require 'sql_footprint/sql_filter'
|
4
5
|
require 'sql_footprint/sql_statements'
|
5
6
|
require 'active_support/notifications'
|
6
7
|
|
7
8
|
module SqlFootprint
|
8
|
-
FILENAME = 'footprint.sql'.freeze
|
9
|
-
NEWLINE = "\n".freeze
|
10
|
-
|
11
9
|
ActiveSupport::Notifications.subscribe('sql.active_record') do |_, _, _, _, payload|
|
12
|
-
capture
|
10
|
+
if @capture
|
11
|
+
adapter = ObjectSpace._id2ref(payload.fetch(:connection_id))
|
12
|
+
database_name = adapter.instance_variable_get(:@config).fetch(:database)
|
13
|
+
capturers[database_name].capture payload.fetch(:sql)
|
14
|
+
end
|
13
15
|
end
|
14
16
|
|
15
17
|
class << self
|
16
|
-
attr_reader :
|
18
|
+
attr_reader :capturers
|
17
19
|
|
18
20
|
def start
|
19
|
-
@
|
20
|
-
@
|
21
|
-
|
22
|
-
|
21
|
+
@capture = true
|
22
|
+
@capturers = Hash.new do |hash, database_name|
|
23
|
+
hash[database_name] = SqlCapturer.new(database_name)
|
24
|
+
end
|
23
25
|
end
|
24
26
|
|
25
27
|
def stop
|
26
28
|
@capture = false
|
27
|
-
|
29
|
+
capturers.values.each(&:write)
|
28
30
|
end
|
29
31
|
|
30
32
|
def exclude
|
@@ -33,10 +35,5 @@ module SqlFootprint
|
|
33
35
|
ensure
|
34
36
|
@capture = true
|
35
37
|
end
|
36
|
-
|
37
|
-
def capture sql
|
38
|
-
return unless @capture && @filter.capture?(sql)
|
39
|
-
@statements.add @anonymizer.anonymize(sql)
|
40
|
-
end
|
41
38
|
end
|
42
39
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sql_footprint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Joyce
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-04
|
13
|
+
date: 2016-05-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -152,12 +152,15 @@ files:
|
|
152
152
|
- .rubocop.yml
|
153
153
|
- .travis.yml
|
154
154
|
- Gemfile
|
155
|
+
- History.md
|
155
156
|
- README.md
|
156
157
|
- Rakefile
|
157
158
|
- bin/console
|
158
159
|
- bin/setup
|
159
160
|
- lib/sql_footprint.rb
|
161
|
+
- lib/sql_footprint/footprint_serializer.rb
|
160
162
|
- lib/sql_footprint/sql_anonymizer.rb
|
163
|
+
- lib/sql_footprint/sql_capturer.rb
|
161
164
|
- lib/sql_footprint/sql_filter.rb
|
162
165
|
- lib/sql_footprint/sql_statements.rb
|
163
166
|
- lib/sql_footprint/version.rb
|