Class: Raven::LineCache

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

Constant Summary collapse

CACHE =

rubocop:disable Style/MutableConstant

{}

Class Method Summary collapse

Class Method Details

.getline(path, n) ⇒ Object



19
20
21
22
23
24
# File 'lib/raven/linecache.rb', line 19

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

.getlines(path) ⇒ Object



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

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

.valid_file?(path) ⇒ Boolean

Returns:

  • (Boolean)


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

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