Module: CloseYourIt::LineCache

Defined in:
lib/closeyourit/line_cache.rb

Overview

Cache in-process delle righe dei file sorgente, per le context lines dei frame (pre_context/context_line/post_context). Bounded: oltre MAX_FILES si svuota per intero — semplice e sufficiente (i file di un'app in errore sono pochi e ricorrenti). Thread-safe.

Constant Summary collapse

MAX_FILES =
200

Class Method Summary collapse

Class Method Details

.clearObject



26
27
28
# File 'lib/closeyourit/line_cache.rb', line 26

def clear
  @mutex.synchronize { @cache.clear }
end

.lines(path) ⇒ Object

Righe del file (chomp-ate), oppure nil se non leggibile o path sintetico ("(eval)", "(irb)").



15
16
17
18
19
20
21
22
23
24
# File 'lib/closeyourit/line_cache.rb', line 15

def lines(path)
  return nil if path.nil? || path.empty? || path.start_with?("(")

  @mutex.synchronize do
    return @cache[path] if @cache.key?(path)

    @cache.clear if @cache.size >= MAX_FILES
    @cache[path] = read_lines(path)
  end
end