class Raven::LineCache

Public Class Methods

new() click to toggle source
# File lib/raven/linecache.rb, line 3
def initialize
  @cache = {}
end

Public Instance Methods

get_file_context(filename, lineno, context) click to toggle source

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.

# 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

Private Instance Methods

getline(path, n) click to toggle source
# File lib/raven/linecache.rb, line 35
def getline(path, n)
  return nil if n < 1

  lines = getlines(path)
  return nil if lines.nil?

  lines[n - 1]
end
getlines(path) click to toggle source
# File lib/raven/linecache.rb, line 27
def getlines(path)
  @cache[path] ||= begin
    IO.readlines(path)
                   rescue
                     nil
  end
end
valid_path?(path) click to toggle source
# File lib/raven/linecache.rb, line 22
def valid_path?(path)
  lines = getlines(path)
  !lines.nil?
end