Class: Annals
- Inherits:
-
Object
- Object
- Annals
- Defined in:
- lib/annals.rb
Instance Attribute Summary collapse
-
#buffer ⇒ Object
Returns the value of attribute buffer.
-
#max ⇒ Object
Returns the value of attribute max.
Instance Method Summary collapse
- #capture(&block) ⇒ Object
-
#initialize(max = 20, &block) ⇒ Annals
constructor
A new instance of Annals.
- #lines ⇒ Object
- #print_lines ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #unshift(line) ⇒ Object
Constructor Details
#initialize(max = 20, &block) ⇒ Annals
Returns a new instance of Annals.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/annals.rb', line 5 def initialize(max = 20, &block) @max = max if block_given? @trace_func = block else @trace_func = lambda { |event, file, line, id, binding, classname| if event == 'call' unshift(:file => file, :line => line, :method => "in #{id}") end } end start end |
Instance Attribute Details
#buffer ⇒ Object
Returns the value of attribute buffer.
3 4 5 |
# File 'lib/annals.rb', line 3 def buffer @buffer end |
#max ⇒ Object
Returns the value of attribute max.
3 4 5 |
# File 'lib/annals.rb', line 3 def max @max end |
Instance Method Details
#capture(&block) ⇒ Object
19 20 21 22 23 |
# File 'lib/annals.rb', line 19 def capture(&block) start yield stop end |
#lines ⇒ Object
25 26 27 |
# File 'lib/annals.rb', line 25 def lines @buffer.map {|event| "#{event[:file]}:#{event[:line]} #{event[:method]}"} end |
#print_lines ⇒ Object
29 30 31 32 33 |
# File 'lib/annals.rb', line 29 def print_lines for line in lines puts(line) end end |
#start ⇒ Object
35 36 37 38 39 40 |
# File 'lib/annals.rb', line 35 def start @buffer = [] @size = 0 Kernel.set_trace_func(@trace_func) true end |
#stop ⇒ Object
42 43 44 45 46 |
# File 'lib/annals.rb', line 42 def stop Kernel.set_trace_func(lambda {}) @buffer.shift # remove Annals#stop from buffer true end |
#unshift(line) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/annals.rb', line 48 def unshift(line) if @size == @max @buffer.pop else @size += 1 end @buffer.unshift(line) end |