indented-tracer 0.1.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.
Files changed (2) hide show
  1. data/lib/indented-tracer.rb +53 -0
  2. metadata +54 -0
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: indented-tracer.rb
4
+
5
+ require 'tracer'
6
+
7
+ class IndentedTracer < Tracer
8
+
9
+ def initialize(classes)
10
+ super
11
+
12
+ add_filter do |event, file, line, id, binding, klass, *rest|
13
+ if klass.to_s[/#{classes.join('|')}/] then
14
+
15
+ if event == 'call' then
16
+
17
+ if @a.nil? then
18
+ @a = []
19
+ @current = @a
20
+
21
+ end
22
+
23
+ @current << [id]
24
+ @grandparent = @parent
25
+ @parent = @current
26
+ @current = @current.last
27
+
28
+ elsif event == 'return'
29
+
30
+ @current = @parent
31
+ @parent = @grandparent
32
+ end
33
+
34
+ end
35
+ end
36
+
37
+ end
38
+
39
+ def log()
40
+ print_all(@a)
41
+ end
42
+
43
+ private
44
+
45
+ def print_all(a, buffer='', indent=0)
46
+ lines = a.map do |x|
47
+ r = (' ' * indent) + x.first.to_s
48
+ x.length > 1 ? r + "\n" + print_all(x[1..-1], buffer, indent+1) : r
49
+ end
50
+ lines.join("\n")
51
+ end
52
+
53
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: indented-tracer
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - James Robertson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2013-01-25 00:00:00 Z
14
+ dependencies: []
15
+
16
+ description:
17
+ email:
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/indented-tracer.rb
26
+ homepage:
27
+ licenses: []
28
+
29
+ post_install_message:
30
+ rdoc_options: []
31
+
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: "0"
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ requirements: []
47
+
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.23
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: indented-tracer
53
+ test_files: []
54
+