annals 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/annals.gemspec +1 -1
- data/lib/annals.rb +14 -9
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/annals.gemspec
CHANGED
data/lib/annals.rb
CHANGED
@@ -4,6 +4,15 @@ class Annals
|
|
4
4
|
|
5
5
|
def initialize(max = 20, &block)
|
6
6
|
@max = max
|
7
|
+
if block_given?
|
8
|
+
@trace_func = block
|
9
|
+
else
|
10
|
+
@trace_func = lambda { |event, file, line, id, binding, classname|
|
11
|
+
if event == 'call'
|
12
|
+
unshift(:file => file, :line => line, :method => "in #{id}")
|
13
|
+
end
|
14
|
+
}
|
15
|
+
end
|
7
16
|
start
|
8
17
|
end
|
9
18
|
|
@@ -17,7 +26,7 @@ class Annals
|
|
17
26
|
@buffer.map {|event| "#{event[:file]}:#{event[:line]} #{event[:method]}"}
|
18
27
|
end
|
19
28
|
|
20
|
-
def
|
29
|
+
def print_lines
|
21
30
|
for line in lines
|
22
31
|
puts(line)
|
23
32
|
end
|
@@ -26,27 +35,23 @@ class Annals
|
|
26
35
|
def start
|
27
36
|
@buffer = []
|
28
37
|
@size = 0
|
29
|
-
Kernel.set_trace_func(
|
30
|
-
|
31
|
-
if event == 'call'
|
32
|
-
unshift(:file => file, :line => line, :method => "in #{id}")
|
33
|
-
end
|
34
|
-
}
|
35
|
-
)
|
38
|
+
Kernel.set_trace_func(@trace_func)
|
39
|
+
true
|
36
40
|
end
|
37
41
|
|
38
42
|
def stop
|
39
43
|
Kernel.set_trace_func(lambda {})
|
40
44
|
@buffer.shift # remove Annals#stop from buffer
|
45
|
+
true
|
41
46
|
end
|
42
47
|
|
43
48
|
def unshift(line)
|
44
|
-
@buffer.unshift(line)
|
45
49
|
if @size == @max
|
46
50
|
@buffer.pop
|
47
51
|
else
|
48
52
|
@size += 1
|
49
53
|
end
|
54
|
+
@buffer.unshift(line)
|
50
55
|
end
|
51
56
|
|
52
57
|
end
|