Class: Raven::LineCache

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

Constant Summary collapse

CACHE =

TODO: a constant isn’t appropriate here, refactor also would there be threading bugs essentially using this as a class variable?

{}

Class Method Summary collapse

Class Method Details

.getline(path, n) ⇒ Object



24
25
26
27
28
29
# File 'lib/raven/linecache.rb', line 24

def getline(path, n)
  return nil if n < 1
  lines = getlines(path)
  return nil if lines.nil?
  lines[n - 1]
end

.getlines(path) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/raven/linecache.rb', line 16

def getlines(path)
  CACHE[path] ||= begin
    IO.readlines(path)
  rescue
    nil
  end
end

.is_valid_file(path) ⇒ Object

rubocop:disable Style/MutableConstant



11
12
13
14
# File 'lib/raven/linecache.rb', line 11

def is_valid_file(path)
  lines = getlines(path)
  !lines.nil?
end