Class: Utils::LineBlamer
Class Method Summary collapse
-
.for_line(line) ⇒ Utils::LineBlamer?
Finds the source location of a line and creates a new LineBlamer instance.
Instance Method Summary collapse
-
#initialize(file, lineno = 1) ⇒ LineBlamer
constructor
Initializes a new LineBlamer instance to analyze source code line information.
-
#perform(options = '') ⇒ String?
Performs git blame on a specific line of code and returns the result.
Constructor Details
#initialize(file, lineno = 1) ⇒ LineBlamer
Initializes a new LineBlamer instance to analyze source code line information.
8 9 10 |
# File 'lib/utils/line_blamer.rb', line 8 def initialize(file, lineno = 1) @file, @lineno = file, lineno end |
Class Method Details
.for_line(line) ⇒ Utils::LineBlamer?
Finds the source location of a line and creates a new LineBlamer instance.
This method extracts the file path and line number from the given line object using its source_location method. If a valid location is found, it initializes and returns a new LineBlamer instance with the extracted file path and line number.
information
has a valid source location, otherwise nil
24 25 26 |
# File 'lib/utils/line_blamer.rb', line 24 def self.for_line(line) location = line.source_location and new(*location) end |
Instance Method Details
#perform(options = '') ⇒ String?
Performs git blame on a specific line of code and returns the result.
This method executes a git blame command to analyze the specified file and line number, retrieving information about when and by whom the line was last modified. It handles potential errors from git by suppressing stderr output and returns nil if git is not available or the operation fails.
39 40 41 |
# File 'lib/utils/line_blamer.rb', line 39 def perform( = '') `git 2>/dev/null blame #{options} -L #@lineno,+1 "#@file"`.full? end |