rails_tracepoint_stack 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rails_tracepoint_stack.rb +33 -10
  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: bf771ac87351c7b8d15333adc88f0c0aa083b249d9522d2ddcf0ded1e979a8a8
4
+ data.tar.gz: '092993f140a76382f146b2afe8c5602d0160d63098b908e089bbc04a5b0e5b53'
5
5
  SHA512:
6
- metadata.gz: e2378072b7de5b60193f238d3f75854de1f21e99fc0f6f18d3210f7c2eef4236538227e99376ae41f108642f3e56d2e39a73fc659afe0a093e10c518295052ca
7
- data.tar.gz: 0fa504f90c0409ec54069efc2fd8e6091ab8f780e92f8082aad7afec018d4af34c6990dba5b3e98f4cb7495540fd76d01a53dee241a3a389de49fc2dfc11ad86
6
+ metadata.gz: daa4d9cfeed7f91e7207c553468ab8bdd31a58a2a57428a3a26bf5deb5c7902b3c8ac44ce2364fe2097eeb3bc242663c8c2564378e063e61c023f27d10204781
7
+ data.tar.gz: fba92e74f76914217347a89eb308f371ccc543c5b69271be363f90585801826787dbf0ba9898d40a5510681502f86598537158e4ba4ae89555b00b59ae1c1a70
@@ -1,17 +1,40 @@
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
40
  trace.disable
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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Daniel Pohlod