Class: Raven::LineCache

Inherits:
Object show all
Defined in:
lib/raven/linecache.rb

Instance Method Summary collapse

Constructor Details

#initializeLineCache

Returns a new instance of LineCache.



3
4
5
# File 'lib/raven/linecache.rb', line 3

def initialize
  @cache = {}
end

Instance Method Details

#get_file_context(filename, lineno, context) ⇒ Object

Any linecache you provide to Raven must implement this method. Returns an Array of Strings representing the lines in the source file. The number of lines retrieved is (2 * context) + 1, the middle line should be the line requested by lineno. See specs for more information.



11
12
13
14
15
16
17
18
# File 'lib/raven/linecache.rb', line 11

def get_file_context(filename, lineno, context)
  return nil, nil, nil unless valid_path?(filename)

  lines = Array.new(2 * context + 1) do |i|
    getline(filename, lineno - context + i)
  end
  [lines[0..(context - 1)], lines[context], lines[(context + 1)..-1]]
end