class Cradare2::Lines::SourceReader

Overview

Reads, caches, and provides contextual snippets of source code files from disk or memory.

Defined in:

cradare2/lines/source_reader.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(search_paths : Array(String) = [] of String) #

[View source]

Instance Method Detail

def clear_cache : Nil #

Clears the cached file contents.


[View source]
def clear_mappings : self #

Clears all path substitution mappings.


[View source]
def exists?(file : String) : Bool #

Returns true if the file exists on disk or in the memory cache.


[View source]
def get_file_lines(file : String) : Array(String) | Nil #

Retrieves all lines of a file, caching them in memory.


[View source]
def has_file?(file : String) : Bool #

Alias for exists?


[View source]
def line_count(file : String) : Int32 #

Returns the total line count for a file, or 0 if not found.


[View source]
def map_path(remote_prefix : String, local_prefix : String) : self #

Configures a path prefix substitution rule (e.g. from container /build/src to local C:/dev/src).


[View source]
def path_mappings : Hash(String, String) #

[View source]
def read_context(file : String, line_num : Int32, before : Int32 = 2, after : Int32 = 2) : Array(NamedTuple(line: Int32, text: String, current: Bool)) #

Reads a contextual block of lines centered around line_num (1-indexed). before and after specify how many surrounding lines to include.


[View source]
def read_context(file : String, line_num : Int32, *, window : Int32) : Array(NamedTuple(line: Int32, text: String, current: Bool)) #

Reads a contextual block of lines centered around line_num with symmetric window keyword.


[View source]
def read_line(file : String, line_num : Int32) : String | Nil #

Reads a single line of text from file at line_num (1-indexed). Returns nil if file or line does not exist.


[View source]
def register_source(file : String, content : String) : Nil #

Adds an in-memory virtual source file (useful for mocking, tests, or slurped source).


[View source]
def resolve_path(file : String) : String | Nil #

Attempts to find the file either as an absolute path, relative to current dir, or relative to one of the configured #search_paths.


[View source]
def search_paths : Array(String) #

[View source]
def set_virtual_source(file : String, content : String) : Nil #

Alias for register_source


[View source]