columns_trace 0.2.0 → 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
  SHA256:
3
- metadata.gz: c654a6d0c0772fffa33bb28544ba4e3299272b2673f8f4a138a4526a16a7f036
4
- data.tar.gz: f8f2d7914dec1d9b1a39182626ba0f37736bdf2b3a618ade7f9cb1b5b204850a
3
+ metadata.gz: 9b9167813d7f9a2089f1eb2380bc62de8289384ed56f33fc4983ca716b76c0a9
4
+ data.tar.gz: 0ce77996e83a1af64bb9d64acc7231965e1a46263b9be30bb870a3e3a0a6a140
5
5
  SHA512:
6
- metadata.gz: 408421ba16b44441a4be3e24c46b0ef7e31bfbcb58d6eacc229c51882c00bd2fbb2956bf16a51572f8d2fab94a9ed515bebb4e8450efdea64b1e849bcffcffb7
7
- data.tar.gz: 3ef7b2f0cf92cce13760dd581ef68a59fe833ce1fe646c9c9c5476ed6163f024efad6bf67732c6f4f338bf92a2a50deed2b560c9b923605d68a2d7d482d6c539
6
+ metadata.gz: a2f63e4cc55f26f7f86670c65378f203e8ea4e703ccd8079e5a4c201729eddb2de42277f654108ef80b61dc29c31ba5211a97fec44f05076480234e65a3221b5
7
+ data.tar.gz: 3fbddc61ae15705ecb191b3d1856f726b292c59d6973b80c4f464555765e423551572fea0e17a21e3019839b9b109e1f0803fc86db588ab9ac3752da8f3d6a3b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## master (unreleased)
2
2
 
3
+ ## 0.3.0 (2023-11-09)
4
+
5
+ - Add ability to trace columns usage in custom code
6
+ - Trace unused columns in mailers
7
+
3
8
  ## 0.2.0 (2023-10-13)
4
9
 
5
10
  - Allow to use custom reporters
data/README.md CHANGED
@@ -25,7 +25,7 @@ $ bundle install
25
25
 
26
26
  ## Usage
27
27
 
28
- Hit a controller action or run `ActiveJob` (or `Sidekiq`) job, open `log/columns_trace.log`,
28
+ Hit a controller or email action or run `ActiveJob` (or `Sidekiq`) job, open `log/columns_trace.log`,
29
29
  and see the output:
30
30
 
31
31
  ```
@@ -54,6 +54,18 @@ ImportProjectJob
54
54
  ↳ app/jobs/import_project_job.rb:24:in `perform'
55
55
  ```
56
56
 
57
+ ### Tracing custom code
58
+
59
+ To get columns usage in the custom code, you can manually wrap it by `ColumnsTrace.report`:
60
+
61
+ ```ruby
62
+ task my_rake_task: :environment do
63
+ ColumnsTrace.report("my_rake_task") do
64
+ # do stuff
65
+ end
66
+ end
67
+ ```
68
+
57
69
  ## Configuration
58
70
 
59
71
  You can override the following default options:
@@ -14,18 +14,20 @@ module ColumnsTrace
14
14
  end
15
15
 
16
16
  ActiveSupport.on_load(:action_controller) do
17
- before_action { Registry.clear }
17
+ around_action do |controller, action|
18
+ ColumnsTrace.report("#{controller.class.name}##{action_name}", &action)
19
+ end
20
+ end
18
21
 
19
- after_action do
20
- ColumnsTrace.reporter.report("#{self.class.name}##{action_name}", Registry.created_records)
22
+ ActiveSupport.on_load(:action_mailer) do
23
+ around_action do |mailer, action|
24
+ ColumnsTrace.report("#{mailer.class.name}##{action_name}", &action)
21
25
  end
22
26
  end
23
27
 
24
28
  ActiveSupport.on_load(:active_job) do
25
- before_perform { Registry.clear }
26
-
27
- after_perform do
28
- ColumnsTrace.reporter.report(self.class.name, Registry.created_records)
29
+ around_perform do |job, perform|
30
+ ColumnsTrace.report("#{job.class.name}#perform", &perform)
29
31
  end
30
32
  end
31
33
  end
@@ -3,10 +3,8 @@
3
3
  module ColumnsTrace
4
4
  # @private
5
5
  class SidekiqMiddleware
6
- def call(worker, _job, _queue)
7
- Registry.clear
8
- yield
9
- ColumnsTrace.reporter.report(worker.class.name, Registry.created_records)
6
+ def call(worker, _job, _queue, &block)
7
+ ColumnsTrace.report("#{worker.class.name}#perform", &block)
10
8
  end
11
9
  end
12
10
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ColumnsTrace
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/columns_trace.rb CHANGED
@@ -11,6 +11,23 @@ require_relative "columns_trace/railtie" if defined?(Rails)
11
11
 
12
12
  module ColumnsTrace
13
13
  class << self
14
+ # Manually trace columns usage in an arbitrary code.
15
+ #
16
+ # @param title [String] title of the reporting, e.g. controller action etc
17
+ #
18
+ # @example
19
+ # task my_rake_task: :environment do
20
+ # ColumnsTrace.report("my_rake_task") do
21
+ # # do stuff
22
+ # end
23
+ # end
24
+ #
25
+ def report(title)
26
+ Registry.clear
27
+ yield
28
+ reporter.report(title, Registry.created_records)
29
+ end
30
+
14
31
  # @private
15
32
  attr_reader :ignored_models
16
33
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: columns_trace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - fatkodima
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-13 00:00:00.000000000 Z
11
+ date: 2023-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord