def update_cache(filename, opts=false)
if opts.kind_of?(Hash)
use_script_lines = opts[:use_script_lines]
else
use_script_lines = opts
opts = {:use_script_lines => use_script_lines}
end
return nil unless filename
@@file_cache.delete(filename)
path = File.expand_path(filename)
if use_script_lines
list = [filename]
list << @@file2file_remap[path] if @@file2file_remap[path]
list.each do |name|
if !SCRIPT_LINES__[name].nil? && SCRIPT_LINES__[name] != true
begin
stat = File.stat(name)
rescue
stat = nil
end
raw_lines = SCRIPT_LINES__[name]
lines = {:plain => raw_lines}
lines[opts[:output]] =
highlight_string(raw_lines.join, opts[:output]).split(/\n/) if
opts[:output]
@@file_cache[filename] = LineCacheInfo.new(stat, nil, lines, path, nil)
@@file2file_remap[path] = filename
return true
end
end
end
if File.exist?(path)
stat = File.stat(path)
elsif File.basename(filename) == filename
stat = nil
for dirname in $:
path = File.join(dirname, filename)
if File.exist?(path)
stat = File.stat(path)
break
end
end
return false unless stat
end
begin
lines = { :plain => File.readlines(path) }
if opts[:output]
lines[opts[:output]] = highlight_string(lines[:plain].join, opts[:output]).split(/\n/)
end
rescue
return nil
end
@@file_cache[filename] = LineCacheInfo.new(File.stat(path), nil, lines,
path, nil)
@@file2file_remap[path] = filename
return true
end