tracia 0.2.3 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 34b3cdfc3aa852818abd808ccb2f108d3999d52ee35168856e2255849d2a5087
4
- data.tar.gz: 5c54033d24d401aeb28b174c3d05b4762850cd72526c594b2b2b108c639f2452
3
+ metadata.gz: 7e8c70f863ced4e60aeeb7d6dc343f568a88df17cb67d039adc7c921fa8149a8
4
+ data.tar.gz: f60c5dc69ccfe8318d5ba951dfbe546e013c87eb0d3641345aaffe96d416d524
5
5
  SHA512:
6
- metadata.gz: a2c36aea77f0cdc14839d69d71d20844c73f11dc5941138b50cb3c87c1d78da95176d18c5f187846980ffcef49467c55fe91a4a85ed3a329b7a4ee7ab3cbfdfa
7
- data.tar.gz: ac94cda876214cc85709a8e8f8a4e834a1b3cb601b08befc38e242bd27e1d35591926552d5943a16d6eb55642e771a19017950905b91c4c1920d24d299fb3414
6
+ metadata.gz: 998c2b5b36a92167c085ca15a0898002c06c5419f9e484342f7b7aa0607bdb8fbdd63c08af26eb219c77d3021828e2bc9a4776cd2d893798d7e0a4d8bb5fd803
7
+ data.tar.gz: 86aa94fb518e44b9498562212c3ad91dbafaadd08af53eb3580b4ae8d07452b5274369d5d99e7b87c93ab38fc9468d17a3e0280f3dca9e5622908ccd227b3978
data/README.md CHANGED
@@ -45,9 +45,9 @@ end
45
45
  By default, Tracia writes result to STDOUT, you can set it somewhere else
46
46
 
47
47
  ```ruby
48
- file = File.new('/path/to/log.txt', 'w+')
48
+ file = File.new('/path/to/log.html', 'w+')
49
49
 
50
- Tracia.start(logger: Tracia::DefaultLogger.new(out: file)) do
50
+ Tracia.start(logger: Tracia::DefaultLogger.new(out: file, html: true)) do
51
51
  # ...
52
52
  end
53
53
  ```
@@ -1,28 +1,13 @@
1
1
  class Tracia
2
2
  class DefaultLogger
3
- NO_CHILD = []
4
-
5
- class << self
6
- def tree_graph_everything!
7
- Object.define_method(:label_for_tree_graph) do
8
- to_s
9
- end
10
-
11
- Object.define_method(:children_for_tree_graph) do
12
- NO_CHILD
13
- end
14
- end
15
- end
16
-
17
- def initialize(out: STDOUT)
3
+ def initialize(out: STDOUT, html: false)
18
4
  @out = out
5
+ @html = html
19
6
  end
20
7
 
21
8
  def call(root)
22
- @out.puts root.tree_graph
23
- rescue => e
24
- @out.puts e.message
25
- @out.puts e.backtrace
9
+ content = @html ? root.tree_html_full : root.tree_graph
10
+ @out.puts content
26
11
  end
27
12
  end
28
13
  end
data/lib/tracia/frame.rb CHANGED
@@ -1,8 +1,11 @@
1
1
  require "tree_graph"
2
+ require "tree_html"
3
+ require "cgi"
2
4
 
3
5
  class Tracia
4
6
  class Frame
5
7
  include TreeGraph
8
+ include TreeHtml
6
9
 
7
10
  attr_reader :klass, :call_sym, :method_name, :children, :file, :lineno
8
11
 
@@ -22,11 +25,42 @@ class Tracia
22
25
  end
23
26
 
24
27
  def label_for_tree_graph
25
- "#{klass}#{call_sym}#{method_name} #{GemPaths.shorten(@file)}:#{@lineno}"
28
+ "#{class_and_method} #{source_location}"
26
29
  end
27
30
 
28
31
  def children_for_tree_graph
29
32
  children
30
33
  end
34
+
35
+ def label_for_tree_html
36
+ "<span class='hl'>#{CGI::escapeHTML(class_and_method)}</span> #{CGI::escapeHTML(source_location)}"
37
+ end
38
+
39
+ def children_for_tree_html
40
+ children
41
+ end
42
+
43
+ def css_for_tree_html
44
+ '.hl{color: #a50000;}'
45
+ end
46
+
47
+ private
48
+
49
+ def class_and_method
50
+ "#{klass}#{call_sym}#{method_name}"
51
+ end
52
+
53
+ INSTANCE_METHOD_SHARP = '#'
54
+
55
+ def source_location
56
+ if @file == nil
57
+ meth = call_sym == INSTANCE_METHOD_SHARP ? klass.instance_method(method_name) : klass.method(method_name)
58
+ src_loc = meth.source_location
59
+ @file = src_loc[0]
60
+ @lineno = src_loc[1]
61
+ end
62
+
63
+ "#{GemPaths.shorten(@file)}:#{@lineno}"
64
+ end
31
65
  end
32
66
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Tracia
4
- VERSION = "0.2.3"
4
+ VERSION = "0.2.6"
5
5
  end
data/lib/tracia.rb CHANGED
@@ -10,8 +10,6 @@ require "binding_of_callers"
10
10
  class Tracia
11
11
  class Error < StandardError; end
12
12
 
13
- INSTANCE_METHOD_SHARP = '#'
14
-
15
13
  attr_accessor :level, :error, :depth
16
14
 
17
15
  class << self
@@ -32,13 +30,14 @@ class Tracia
32
30
  trc.log if trc.level == 0
33
31
  end
34
32
 
35
- def add(info)
33
+ def add(info = nil, &block)
36
34
  trc = Thread.current[:_tracia_]
37
35
  return unless trc
38
36
 
39
37
  backtrace = binding.partial_callers(-trc.depth)
40
38
  backtrace.reverse!
41
39
  backtrace.pop
40
+ info = block.call if block
42
41
  trc.add(backtrace, info)
43
42
  end
44
43
  end
@@ -141,6 +140,8 @@ class Tracia
141
140
  @frames_to_reject.any?{ |rj| rj =~ raw_frame.file }
142
141
  end
143
142
 
143
+ EMPTY_SRC_LOC = []
144
+
144
145
  def convert_to_frames(callers)
145
146
  callers.map! do |c|
146
147
  _binding = c._binding
@@ -150,8 +151,9 @@ class Tracia
150
151
 
151
152
  source_location =
152
153
  if _binding.frame_type == :method
153
- meth = call_symbol == INSTANCE_METHOD_SHARP ? klass.instance_method(frame_env) : klass.method(frame_env)
154
- meth.source_location
154
+ # meth = call_symbol == INSTANCE_METHOD_SHARP ? klass.instance_method(frame_env) : klass.method(frame_env)
155
+ # meth.source_location
156
+ EMPTY_SRC_LOC
155
157
  else
156
158
  _binding.source_location
157
159
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tracia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - ken
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-18 00:00:00.000000000 Z
11
+ date: 2022-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -30,14 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.2.2
33
+ version: 0.2.4
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.2.2
40
+ version: 0.2.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: tree_html
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.8
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.8
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: binding_of_callers
43
57
  requirement: !ruby/object:Gem::Requirement