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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2808176972e7b35b01a34cc34f9894a7c0e09d4
4
- data.tar.gz: b67e95f379439301c92c2f66d17b24f8a253ef1c
3
+ metadata.gz: 496830234a8ea90773d91b585d7ec937671b5712
4
+ data.tar.gz: 4f0ec6e6b1fb20d5b95eb78057ba883006c00d7a
5
5
  SHA512:
6
- metadata.gz: cb580a2acecdda22e4f09c6933f421279c443be4d4f22ee85b1be43e8d8d5501cb123caff8439c5683abfa15f22a648589699779706aa9cea2c4e3faa19a441b
7
- data.tar.gz: ae06d0b3d619a26eeca98b71872e2d414d172227d64cd22e2bd55888c75a23e781cd7610139346118eb29afb285f344344fc7d0ab4c54792a0b91032f34049e7
6
+ metadata.gz: 90e16e7c7ac1fae49f14d38c453cfe36324e9d3fdf6c2aadfdf9e829b343f3fbd13ec75c30d614d0f6f6c87064bdadfee811f60870155dd24688592723e58eda
7
+ data.tar.gz: 1a82424a427d0544dfcbb6d12eaacad5f0e5b0cdab79ec455be763905b70b2d6d8e1b54be3579f46221aed78b4d00fcee744fe1afba756bd2aacd57085df9b2a
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  footprint.sql
11
+ footprint.:memory:.sql
data/History.md ADDED
@@ -0,0 +1,5 @@
1
+
2
+ 1.0.0 / 2016-05-04
3
+ ==================
4
+
5
+ * Split footprint files by database name
@@ -0,0 +1,13 @@
1
+ module SqlFootprint
2
+ class FootprintSerializer
3
+ NEWLINE = "\n".freeze
4
+
5
+ def initialize statements
6
+ @statements = statements
7
+ end
8
+
9
+ def to_s
10
+ @statements.sort.join(NEWLINE) + NEWLINE
11
+ end
12
+ end
13
+ end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module SqlFootprint
2
- VERSION = '0.8.0'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  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 payload.fetch(:sql)
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 :statements
18
+ attr_reader :capturers
17
19
 
18
20
  def start
19
- @anonymizer = SqlAnonymizer.new
20
- @filter = SqlFilter.new
21
- @capture = true
22
- @statements = SqlStatements.new
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
- File.write FILENAME, statements.sort.join(NEWLINE) + NEWLINE
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.8.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-15 00:00:00.000000000 Z
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