rails_tracepoint_stack 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eeb97f7192b4379bdebd15da84477298535c897236b3a3acb2735f89db5ebd7b
4
- data.tar.gz: 809557f925e2fd9e85302eef08497792ccc525b3f5b25662266fc4f6cc76e770
3
+ metadata.gz: 874f14c9b66717408755c8bae182634b457f23ae684ec5cc6eb1bb2b07aa5865
4
+ data.tar.gz: e23e31fd3558896656efbb58796d9fc689f535b0835e646602eaa3590fba89af
5
5
  SHA512:
6
- metadata.gz: a903d86229c926bbfcbcbeb75971c3aa2891b35327fe6608ce29c6b88f2c7f3e97c135d66c9783f0632fd9286a88df558be187389b9332f0407431878ff65cdc
7
- data.tar.gz: d65ba8f3c6fb40c9c2a505dd8cc771f8de357dc0dc5de724ba7a118f8f772dd66773c4dd6cf087d8c3c3bce4c05d75bc35fa0cf7d52c98cb874213204b8b70ac
6
+ metadata.gz: 13efe4146269be0aa124022ca0b7fca5eaa8a91611a9a8e1f59af24d82af70f815f9853b0a4b93b5c1dd7de9401af13341e82f59b5ace70a0b47b1298b446c6c
7
+ data.tar.gz: 0bdc7578909e62f51dddf52b65e2de7a37d7afc1f8cdf794427bfda3e022ac1396627c3ffc2e5ee117fd322f81f1ec4f54ebad2172ffb2571779e8c890ff8bc3
@@ -0,0 +1,10 @@
1
+ module RailsTracepointStack
2
+ class Configuration
3
+ attr_accessor :ignore_patterns, :logger
4
+
5
+ def initialize
6
+ @ignore_patterns = []
7
+ @logger = nil
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ module RailsTracepointStack
2
+ class Logger
3
+ def self.log(msg)
4
+ unless RailsTracepointStack.configuration&.logger
5
+ File.open('log/rails_tracepoint_stack.log', 'a') do |f|
6
+ f.puts msg
7
+ end
8
+ else
9
+ RailsTracepointStack.configuration.logger.info(msg)
10
+ end
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,31 @@
1
+ module RailsTracepointStack
2
+ class TraceFilter
3
+ def self.ignore_trace?(trace:)
4
+ start_with_to_ignore_prefixes?(trace) || from_gempath_or_lib_path?(trace) || is_a_to_ignore_pattern?(trace)
5
+ end
6
+
7
+ private
8
+
9
+ def self.gem_paths
10
+ @gem_paths ||= Bundler.load.specs.map(&:full_gem_path)
11
+ end
12
+
13
+ def self.ruby_lib_path
14
+ @ruby_lib_path ||= RbConfig::CONFIG['rubylibdir']
15
+ end
16
+
17
+ def self.start_with_to_ignore_prefixes?(trace)
18
+ trace.path.start_with?('<internal:') || trace.path == '(eval)'
19
+ end
20
+
21
+ def self.from_gempath_or_lib_path?(trace)
22
+ gem_paths.any? { |path| trace.path.start_with?(path) } ||
23
+ trace.path.start_with?(ruby_lib_path) ||
24
+ trace.path.include?("gems/bundler")
25
+ end
26
+
27
+ def self.is_a_to_ignore_pattern?(trace)
28
+ RailsTracepointStack.configuration&.ignore_patterns&.any? { |pattern| trace.path.match?(pattern) }
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,25 @@
1
+ require 'rails_tracepoint_stack/logger'
2
+ require 'rails_tracepoint_stack/trace_filter'
3
+
4
+ module RailsTracepointStack
5
+ class Tracer
6
+ def tracer
7
+ @trace ||= TracePoint.new(:call) do |tp|
8
+ next if RailsTracepointStack::TraceFilter.ignore_trace?(trace: tp)
9
+
10
+ params = fetch_params(tp)
11
+
12
+ RailsTracepointStack::Logger.log "called: #{tp.defined_class}##{tp.method_id} in #{tp.path}:#{tp.lineno} with params: #{params}"
13
+ end
14
+ end
15
+
16
+ private
17
+ attr_reader :gem_paths, :ruby_lib_path
18
+
19
+ def fetch_params(tp)
20
+ tp.binding.local_variables.map { |var|
21
+ [var, tp.binding.local_variable_get(var)]
22
+ }.to_h
23
+ end
24
+ end
25
+ end
@@ -1,41 +1,34 @@
1
+ require 'rails_tracepoint_stack/configuration'
2
+ require 'rails_tracepoint_stack/tracer'
1
3
 
2
- class TracepointStack
3
- def initialize
4
- @gem_paths = Bundler.load.specs.map(&:full_gem_path)
5
- @ruby_lib_path = RbConfig::CONFIG['rubylibdir']
6
- end
4
+ $rails_tracer_rtps = nil
7
5
 
8
- def tracer
9
- @trace ||= TracePoint.new(:call) do |tp|
10
- next if start_with_to_ignore_prefixes?(tp) || from_gempath_or_lib_path?(tp)
11
-
12
- params = fetch_params(tp)
13
-
14
- puts "called: #{tp.defined_class}##{tp.method_id} in #{tp.path}:#{tp.lineno} with params: #{params}"
15
- end
6
+ module RailsTracepointStack
7
+ class << self
8
+ attr_accessor :configuration, :logger
16
9
  end
17
10
 
18
- private
19
- attr_reader :gem_paths, :ruby_lib_path
20
-
21
- def fetch_params(tp)
22
- tp.binding.local_variables.map { |var|
23
- [var, tp.binding.local_variable_get(var)]
24
- }.to_h
11
+ def self.configure
12
+ self.configuration ||= RailsTracepointStack::Configuration.new
13
+ yield(configuration)
25
14
  end
26
15
 
27
- def start_with_to_ignore_prefixes?(tp)
28
- tp.path.start_with?('<internal:') || tp.path == '(eval)'
29
- end
16
+ def self.enable_trace
17
+ raise ArgumentError, "Block not given to #enable_trace" unless block_given?
30
18
 
31
- def from_gempath_or_lib_path?(tp)
32
- gem_paths.any? { |path| tp.path.start_with?(path) } || tp.path.start_with?(ruby_lib_path)
19
+ tracer = RailsTracepointStack::Tracer.new.tracer
20
+ tracer.enable
21
+ yield
22
+ ensure
23
+ tracer.disable
33
24
  end
34
25
  end
35
26
 
36
- tracer = TracepointStack.new.tracer
37
- tracer.enable
27
+ if ENV.fetch('RAILS_TRACEPOINT_STACK', 'false') == 'true'
28
+ $rails_tracer_rtps = RailsTracepointStack::Tracer.new.tracer
29
+ $rails_tracer_rtps.enable
38
30
 
39
- at_exit do
40
- tracer.disable
31
+ at_exit do
32
+ $rails_tracer_rtps.disable
33
+ end
41
34
  end
metadata CHANGED
@@ -1,15 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_tracepoint_stack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Daniel Pohlod
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-16 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-07-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '6.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 6.0.0
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '6.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 6.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '12.0'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 12.0.0
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '12.0'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 12.0.0
13
53
  description: A formatted output of all methods called in your rails application of
14
54
  code created by the developer, with the complete path to the class/module, including
15
55
  passed params.
@@ -19,10 +59,16 @@ extensions: []
19
59
  extra_rdoc_files: []
20
60
  files:
21
61
  - lib/rails_tracepoint_stack.rb
62
+ - lib/rails_tracepoint_stack/configuration.rb
63
+ - lib/rails_tracepoint_stack/logger.rb
64
+ - lib/rails_tracepoint_stack/trace_filter.rb
65
+ - lib/rails_tracepoint_stack/tracer.rb
22
66
  homepage: https://github.com/carlosdanielpohlod/rails_tracepoint_stack/
23
67
  licenses:
24
68
  - MIT
25
- metadata: {}
69
+ metadata:
70
+ documentation_uri: https://github.com/carlosdanielpohlod/rails_tracepoint_stack/
71
+ changelog_uri: https://github.com/carlosdanielpohlod/rails_tracepoint_stack/blob/main/changelog.md
26
72
  post_install_message:
27
73
  rdoc_options: []
28
74
  require_paths:
@@ -31,7 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
31
77
  requirements:
32
78
  - - ">="
33
79
  - !ruby/object:Gem::Version
34
- version: '0'
80
+ version: '3.0'
35
81
  required_rubygems_version: !ruby/object:Gem::Requirement
36
82
  requirements:
37
83
  - - ">="