Module: Tracee::Stack

Defined in:
lib/tracee/stack.rb,
lib/tracee/stack/base_decorator.rb

Defined Under Namespace

Modules: BaseDecorator

Constant Summary collapse

SCRIPT_LINES_MTIMES =
{}

Class Method Summary collapse

Class Method Details

.readline(file, line) ⇒ Object



37
38
39
40
41
# File 'lib/tracee/stack.rb', line 37

def self.readline(file, line)
  if lines = readlines(file)
    (lines[line.to_i - 1] || "<line #{line} is not found> ").chomp
  end
end

.readlines(file) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/tracee/stack.rb', line 13

def self.readlines(file)
  if reload_script_lines
    if File.exists?(file)
      mtime = File.mtime(file)
      unless SCRIPT_LINES_MTIMES[file] and SCRIPT_LINES_MTIMES[file] >= mtime
        SCRIPT_LINES_MTIMES[file] = mtime
        SCRIPT_LINES__[file] = IO.readlines(file)
      end
      SCRIPT_LINES__[file]
    elsif lines = SCRIPT_LINES__[file]
      lines
    end
  else
    if lines = SCRIPT_LINES__[file]
      lines
    else
      if File.exists?(file)
        SCRIPT_LINES_MTIMES[file] = File.mtime(file)
        SCRIPT_LINES__[file] = IO.readlines(file)
      end
    end
  end
end