Class: Sentry::LineCache Private

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

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initializeLineCache

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of LineCache.



6
7
8
# File 'lib/sentry/linecache.rb', line 6

def initialize
  @cache = {}
end

Instance Method Details

#get_file_context(filename, lineno, context) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Any linecache you provide to Sentry 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.



14
15
16
17
18
19
20
21
# File 'lib/sentry/linecache.rb', line 14

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