class
Cradare2::Lines::SourceReader
- Cradare2::Lines::SourceReader
- Reference
- Object
Overview
Reads, caches, and provides contextual snippets of source code files from disk or memory.
Defined in:
cradare2/lines/source_reader.crConstructors
Instance Method Summary
-
#clear_cache : Nil
Clears the cached file contents.
-
#clear_mappings : self
Clears all path substitution mappings.
-
#exists?(file : String) : Bool
Returns true if the file exists on disk or in the memory cache.
-
#get_file_lines(file : String) : Array(String) | Nil
Retrieves all lines of a file, caching them in memory.
-
#has_file?(file : String) : Bool
Alias for exists?
-
#line_count(file : String) : Int32
Returns the total line count for a file, or 0 if not found.
-
#map_path(remote_prefix : String, local_prefix : String) : self
Configures a path prefix substitution rule (e.g.
- #path_mappings : Hash(String, String)
-
#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). -
#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_numwith symmetric window keyword. -
#read_line(file : String, line_num : Int32) : String | Nil
Reads a single line of text from
fileatline_num(1-indexed). -
#register_source(file : String, content : String) : Nil
Adds an in-memory virtual source file (useful for mocking, tests, or slurped source).
-
#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. - #search_paths : Array(String)
-
#set_virtual_source(file : String, content : String) : Nil
Alias for register_source
Constructor Detail
Instance Method Detail
Retrieves all lines of a file, caching them in memory.
Configures a path prefix substitution rule (e.g. from container /build/src to local C:/dev/src).
Reads a contextual block of lines centered around line_num (1-indexed).
before and after specify how many surrounding lines to include.
Reads a contextual block of lines centered around line_num with symmetric window keyword.
Reads a single line of text from file at line_num (1-indexed).
Returns nil if file or line does not exist.
Adds an in-memory virtual source file (useful for mocking, tests, or slurped source).
Attempts to find the file either as an absolute path, relative to current dir,
or relative to one of the configured #search_paths.