tp_tree 0.1.0 → 0.1.1
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/tp_tree/interactive_viewer.rb +3 -3
- data/lib/tp_tree/tree_node.rb +20 -2
- data/lib/tp_tree/version.rb +1 -1
- metadata +1 -2
- data/lib/tp_tree/xml_formatter.rb +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6faa596f1d2073c36101aa45c28a74f5247fc5445053a5cc3edaf86c1c3e8d04
|
4
|
+
data.tar.gz: 9c539fb05f5fb9c2fc011ea8a08a633a6e06fb76469fb8cac5afbd5cb52449be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b081974e2357c41e44748f159cea9e863ef18052b7a35f46b5ac3f5979242314450411e8ce0d726f8e1dfb704681420c8c63e5efa5dca3440077c3c4aa1fcfa
|
7
|
+
data.tar.gz: 8ab69ea0d94a758bc368de22fa44b94874c144463d986aa282168228f0d26f7ff075d681f96d1d95664956ac49836e78ae1a4c867d0a15c677d20e62c224a849
|
data/README.md
CHANGED
@@ -93,7 +93,7 @@ end
|
|
93
93
|
Export trace data for external analysis:
|
94
94
|
|
95
95
|
```ruby
|
96
|
-
TPTree.catch(
|
96
|
+
TPTree.catch(write_to: 'trace.json') do
|
97
97
|
# your code
|
98
98
|
end
|
99
99
|
```
|
@@ -106,7 +106,7 @@ The JSON file contains structured data with timing, parameters, return values, a
|
|
106
106
|
TPTree.catch(
|
107
107
|
filter: 'important_method', # Method filtering
|
108
108
|
exclude: 'noise_method', # Method exclusion
|
109
|
-
|
109
|
+
write_to: 'trace.json', # JSON export
|
110
110
|
interactive: true # Interactive viewer (if available)
|
111
111
|
) do
|
112
112
|
# your code
|
@@ -2,12 +2,11 @@
|
|
2
2
|
|
3
3
|
require 'curses'
|
4
4
|
require 'set'
|
5
|
-
require_relative 'xml_formatter'
|
5
|
+
require_relative 'formatters/xml_formatter'
|
6
6
|
require_relative 'tree_node'
|
7
7
|
|
8
8
|
module TPTree
|
9
9
|
class InteractiveViewer
|
10
|
-
include XMLFormatter
|
11
10
|
|
12
11
|
def initialize(tree)
|
13
12
|
@tree = tree
|
@@ -20,6 +19,7 @@ module TPTree
|
|
20
19
|
@stdscr = Curses.init_screen
|
21
20
|
@expanded_nodes = Set.new
|
22
21
|
@node_children = {}
|
22
|
+
@formatter = Formatters::XmlFormatter.new
|
23
23
|
|
24
24
|
# Initialize all nodes as expanded and build parent-child relationships
|
25
25
|
analyze_tree_structure
|
@@ -168,7 +168,7 @@ module TPTree
|
|
168
168
|
|
169
169
|
def prepare_lines
|
170
170
|
@lines = @tree.map do |node|
|
171
|
-
node.to_parts(formatter:
|
171
|
+
node.to_parts(formatter: @formatter)
|
172
172
|
end
|
173
173
|
end
|
174
174
|
|
data/lib/tp_tree/tree_node.rb
CHANGED
@@ -89,7 +89,15 @@ module TPTree
|
|
89
89
|
|
90
90
|
def serialize_value(value)
|
91
91
|
case value
|
92
|
-
when String
|
92
|
+
when String
|
93
|
+
# Handle binary strings that can't be converted to UTF-8
|
94
|
+
if value.encoding == Encoding::ASCII_8BIT || !value.valid_encoding?
|
95
|
+
# For binary data, show type and size instead of content
|
96
|
+
"[Binary data: #{value.bytesize} bytes]"
|
97
|
+
else
|
98
|
+
value
|
99
|
+
end
|
100
|
+
when Symbol, NilClass, TrueClass, FalseClass, Numeric
|
93
101
|
value
|
94
102
|
when Array
|
95
103
|
value.map { |v| serialize_value(v) }
|
@@ -98,7 +106,17 @@ module TPTree
|
|
98
106
|
when Proc
|
99
107
|
'Proc'
|
100
108
|
else
|
101
|
-
|
109
|
+
# Safely inspect objects, handling encoding issues
|
110
|
+
begin
|
111
|
+
inspected = value.inspect
|
112
|
+
if inspected.valid_encoding?
|
113
|
+
inspected
|
114
|
+
else
|
115
|
+
"[Object: #{value.class}]"
|
116
|
+
end
|
117
|
+
rescue Encoding::UndefinedConversionError, Encoding::InvalidByteSequenceError
|
118
|
+
"[Object: #{value.class}]"
|
119
|
+
end
|
102
120
|
end
|
103
121
|
end
|
104
122
|
end
|
data/lib/tp_tree/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tp_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmytro Koval
|
@@ -41,7 +41,6 @@ files:
|
|
41
41
|
- lib/tp_tree/tree_builder.rb
|
42
42
|
- lib/tp_tree/tree_node.rb
|
43
43
|
- lib/tp_tree/version.rb
|
44
|
-
- lib/tp_tree/xml_formatter.rb
|
45
44
|
- sig/tp_tree.rbs
|
46
45
|
homepage: https://github.com/dmk/tp_tree
|
47
46
|
licenses:
|
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'formatters/xml_formatter'
|
4
|
-
|
5
|
-
module TPTree
|
6
|
-
# XMLFormatter provides methods for colorizing and formatting output using XML tags.
|
7
|
-
# This module acts as a compatibility layer for the old XMLFormatter module.
|
8
|
-
module XMLFormatter
|
9
|
-
def self.included(base)
|
10
|
-
base.extend(FormatterMethods)
|
11
|
-
base.include(FormatterMethods)
|
12
|
-
end
|
13
|
-
|
14
|
-
module FormatterMethods
|
15
|
-
def formatter
|
16
|
-
@xml_formatter ||= Formatters::XmlFormatter.new
|
17
|
-
end
|
18
|
-
|
19
|
-
def colorize(text, color)
|
20
|
-
formatter.colorize(text, color)
|
21
|
-
end
|
22
|
-
|
23
|
-
def format_timing(duration)
|
24
|
-
formatter.format_timing(duration)
|
25
|
-
end
|
26
|
-
|
27
|
-
def format_parameters(parameters)
|
28
|
-
formatter.format_parameters(parameters)
|
29
|
-
end
|
30
|
-
|
31
|
-
def format_value(value)
|
32
|
-
formatter.format_value(value)
|
33
|
-
end
|
34
|
-
|
35
|
-
def format_return_value(return_value)
|
36
|
-
formatter.format_return_value(return_value)
|
37
|
-
end
|
38
|
-
|
39
|
-
def color_for_depth(depth)
|
40
|
-
formatter.color_for_depth(depth)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# Expose constants for backward compatibility
|
45
|
-
DEPTH_COLORS = Formatters::BaseFormatter::DEPTH_COLORS
|
46
|
-
end
|
47
|
-
end
|