Module: LineCache

Module | LineCache
In: | lib/linecache.rb lib/linecache.rb

# module LineCache

Module caching lines of a file

### Methods

cache cache cached? cached? cached_files cached_files cached_script? cached_script? checkcache checkcache clear_file_cache clear_file_cache empty? empty? getline getline getlines getlines path path remap_file remap_file remap_file_lines remap_file_lines sha1 sha1 size size stat stat trace_line_numbers trace_line_numbers unmap_file unmap_file unmap_file_line unmap_file_line update_cache update_cache

### Constants

LineCacheInfo | = | Struct.new(:stat, :line_numbers, :lines, :path, :sha1) unless defined?(LineCacheInfo)
LineCacheInfo | = | Struct.new(:stat, :line_numbers, :lines, :path, :sha1) unless defined?(LineCacheInfo)

### Public Instance methods

cache(filename, reload_on_change=false)

Cache filename if it‘s not already cached. Return the expanded filename for it in the cache or nil if we can‘t find the file.

cache(filename, reload_on_change=false)

Cache filename if it‘s not already cached. Return the expanded filename for it in the cache or nil if we can‘t find the file.

cached?(filename)

Return true if filename is cached

cached?(filename)

Return true if filename is cached

cached_files()

Return an array of cached file names

cached_files()

Return an array of cached file names

cached_script?(filename)
cached_script?(filename)
checkcache(filename=nil, use_script_lines=false)

Discard cache entries that are out of date. If `filename` is `nil` all entries in the file cache +@@file_cache+ are checked. If we don‘t have stat information about a file which can happen if the file was read from __SCRIPT_LINES but no corresponding file is found, it will be kept. Return a list of invalidated filenames. nil is returned if a filename was given but not found cached.

checkcache(filename=nil, use_script_lines=false)

Discard cache entries that are out of date. If `filename` is `nil` all entries in the file cache +@@file_cache+ are checked. If we don‘t have stat information about a file which can happen if the file was read from __SCRIPT_LINES but no corresponding file is found, it will be kept. Return a list of invalidated filenames. nil is returned if a filename was given but not found cached.

clear_file_cache()

Clear the file cache entirely.

clear_file_cache()

Clear the file cache entirely.

empty?(filename)
empty?(filename)
getline(filename, line_number, reload_on_change=true)

Get line `line_number` from file named `filename`. Return nil if there was a problem. If a file named filename is not found, the function will look for it in the $: path array.

Examples:

     lines = LineCache::getline('/tmp/myfile.rb)
     # Same as above
     $: << '/tmp'
     lines = Dir.chdir('/tmp') do
        lines = LineCache::getlines ('myfile.rb')
     end

getline(filename, line_number, reload_on_change=true)

Get line `line_number` from file named `filename`. Return nil if there was a problem. If a file named filename is not found, the function will look for it in the $: path array.

Examples:

     lines = LineCache::getline('/tmp/myfile.rb)
     # Same as above
     $: << '/tmp'
     lines = Dir.chdir('/tmp') do
        lines = LineCache::getlines ('myfile.rb')
     end

getlines(filename, reload_on_change=false)

Read lines of `filename` and cache the results. However `filename` was previously cached use the results from the cache. Return nil if we can‘t get lines

getlines(filename, reload_on_change=false)

Read lines of `filename` and cache the results. However `filename` was previously cached use the results from the cache. Return nil if we can‘t get lines

path(filename)

Return full filename path for filename

path(filename)

Return full filename path for filename

remap_file(from_file, to_file)
remap_file(from_file, to_file)
remap_file_lines(from_file, to_file, range, start)
remap_file_lines(from_file, to_file, range, start)
sha1(filename)

Return SHA1 of filename.

sha1(filename)

Return SHA1 of filename.

size(filename)

Return the number of lines in filename

size(filename)

Return the number of lines in filename

stat(filename)

Return File.stat in the cache for filename.

stat(filename)

Return File.stat in the cache for filename.

trace_line_numbers(filename, reload_on_change=false)

Return an Array of breakpoints in filename. The list will contain an entry for each distinct line event call so it is possible (and possibly useful) for a line number appear more than once.

trace_line_numbers(filename, reload_on_change=false)

Return an Array of breakpoints in filename. The list will contain an entry for each distinct line event call so it is possible (and possibly useful) for a line number appear more than once.

unmap_file(file)
unmap_file(file)
unmap_file_line(file, line)
unmap_file_line(file, line)
update_cache(filename, use_script_lines=false)

Update a cache entry. If something‘s wrong, return nil. Return true if the cache was updated and false if not. If use_script_lines is true, use that as the source for the lines of the file

update_cache(filename, use_script_lines=false)

Update a cache entry. If something‘s wrong, return nil. Return true if the cache was updated and false if not. If use_script_lines is true, use that as the source for the lines of the file

[Validate]