traceologist 0.1.0 → 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 +4 -4
- data/README.md +2 -2
- data/lib/traceologist/version.rb +1 -1
- data/lib/traceologist.rb +6 -6
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4adb6bbde552ca8fd7a4190bb6e10176a5b4811c43576674f42572c01875fc6f
|
|
4
|
+
data.tar.gz: 641956783b73b1a1f9d9f0e138a6e84dd05341cd751db9d8dad30b9ac5430a24
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 492a2cd1569bda726ee3eb9cc42bcd47915d6cc64488815765465888006fbf65d6707b3cc324f79886720ce22ce7fd73e045668dfadc8baf8ffa549a35bf0401
|
|
7
|
+
data.tar.gz: 78caa58b53a7cb131cb68572208231c33e9f7bd314d7c73b07b98528e963410c56e5f8219fb1ac61b22362bf2a2fbb53c419f16c7066243a30b21a333b6a3ece
|
data/README.md
CHANGED
|
@@ -74,10 +74,10 @@ Without a filter, **all** Ruby method calls within the block are traced.
|
|
|
74
74
|
Traceologist.trace_sequence(depth_limit: 5, filter: "MyClass") { ... }
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
#### `
|
|
77
|
+
#### `show_locations:` — Include source file and line number
|
|
78
78
|
|
|
79
79
|
```ruby
|
|
80
|
-
result = Traceologist.trace_sequence(filter: "MyClass",
|
|
80
|
+
result = Traceologist.trace_sequence(filter: "MyClass", show_locations: true) do
|
|
81
81
|
MyClass.new.run
|
|
82
82
|
end
|
|
83
83
|
```
|
data/lib/traceologist/version.rb
CHANGED
data/lib/traceologist.rb
CHANGED
|
@@ -23,23 +23,23 @@ module Traceologist
|
|
|
23
23
|
# @param depth_limit [Integer] Maximum call depth to trace (default: 20)
|
|
24
24
|
# @param filter [String, Symbol, Array<String, Symbol>, nil] Only trace classes whose name
|
|
25
25
|
# starts with one of these prefixes. When nil, all calls are traced.
|
|
26
|
-
# @param
|
|
26
|
+
# @param show_locations [Boolean] Whether to include source file and line number (default: false)
|
|
27
27
|
# @yield The block of code to trace
|
|
28
28
|
# @return [Traceologist::String] The call sequence as a newline-joined string
|
|
29
29
|
#
|
|
30
30
|
# @example
|
|
31
31
|
# result = Traceologist.trace_sequence(filter: "MyClass") { MyClass.new.run }
|
|
32
32
|
# puts result
|
|
33
|
-
def self.trace_sequence(depth_limit: 20, filter: nil,
|
|
34
|
-
Tracer.new(depth_limit: depth_limit, filter: filter,
|
|
33
|
+
def self.trace_sequence(depth_limit: 20, filter: nil, show_locations: false, &)
|
|
34
|
+
Tracer.new(depth_limit: depth_limit, filter: filter, show_locations: show_locations).run(&)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
# @api private
|
|
38
38
|
class Tracer
|
|
39
|
-
def initialize(depth_limit:, filter:,
|
|
39
|
+
def initialize(depth_limit:, filter:, show_locations:)
|
|
40
40
|
@depth_limit = depth_limit
|
|
41
41
|
@filter = filter
|
|
42
|
-
@
|
|
42
|
+
@show_locations = show_locations
|
|
43
43
|
@depth = 0
|
|
44
44
|
@call_stack = []
|
|
45
45
|
@calls = []
|
|
@@ -86,7 +86,7 @@ module Traceologist
|
|
|
86
86
|
|
|
87
87
|
def call_line(event)
|
|
88
88
|
indent = " " * @depth
|
|
89
|
-
location = @
|
|
89
|
+
location = @show_locations ? " # #{event.path}:#{event.lineno}" : ""
|
|
90
90
|
"#{indent}-> #{label(event)}#{location}"
|
|
91
91
|
end
|
|
92
92
|
|