rails_tracepoint_stack 0.1.1 → 0.1.3

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rails_tracepoint_stack.rb +34 -11
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dddf526a8f20e981620b1480df39a8c98fa098282ec70ff65adc7d074c5220ad
4
- data.tar.gz: 6f10e166a3d0cf9c716cba7d82888df6b33caedf143360818fe8a1df5463cf05
3
+ metadata.gz: eeb97f7192b4379bdebd15da84477298535c897236b3a3acb2735f89db5ebd7b
4
+ data.tar.gz: 809557f925e2fd9e85302eef08497792ccc525b3f5b25662266fc4f6cc76e770
5
5
  SHA512:
6
- metadata.gz: e2378072b7de5b60193f238d3f75854de1f21e99fc0f6f18d3210f7c2eef4236538227e99376ae41f108642f3e56d2e39a73fc659afe0a093e10c518295052ca
7
- data.tar.gz: 0fa504f90c0409ec54069efc2fd8e6091ab8f780e92f8082aad7afec018d4af34c6990dba5b3e98f4cb7495540fd76d01a53dee241a3a389de49fc2dfc11ad86
6
+ metadata.gz: a903d86229c926bbfcbcbeb75971c3aa2891b35327fe6608ce29c6b88f2c7f3e97c135d66c9783f0632fd9286a88df558be187389b9332f0407431878ff65cdc
7
+ data.tar.gz: d65ba8f3c6fb40c9c2a505dd8cc771f8de357dc0dc5de724ba7a118f8f772dd66773c4dd6cf087d8c3c3bce4c05d75bc35fa0cf7d52c98cb874213204b8b70ac
@@ -1,18 +1,41 @@
1
- gem_paths = Bundler.load.specs.map(&:full_gem_path)
2
- ruby_lib_path = RbConfig::CONFIG['rubylibdir']
3
1
 
4
- trace = TracePoint.new(:call) do |tp|
5
- next if tp.path.start_with?('<internal:') || tp.path == '(eval)' || gem_paths.any? { |path| tp.path.start_with?(path) } || tp.path.start_with?(ruby_lib_path)
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
6
7
 
7
- params = tp.binding.local_variables.map { |var|
8
- [var, tp.binding.local_variable_get(var)]
9
- }.to_h
10
-
11
- puts "called: #{tp.defined_class}##{tp.method_id} in #{tp.path}:#{tp.lineno} with params: #{params}"
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
16
+ end
17
+
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
25
+ end
26
+
27
+ def start_with_to_ignore_prefixes?(tp)
28
+ tp.path.start_with?('<internal:') || tp.path == '(eval)'
29
+ end
30
+
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)
33
+ end
12
34
  end
13
35
 
14
- trace.enable
36
+ tracer = TracepointStack.new.tracer
37
+ tracer.enable
15
38
 
16
39
  at_exit do
17
- trace.disable
40
+ tracer.disable
18
41
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_tracepoint_stack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Daniel Pohlod