instance method
find_lineno_offset
Ruby on Rails 8.1.2
Since v8.1.2 PrivateSignature
find_lineno_offset(compiled, source_lines, highlight, error_lineno)
Return the offset between the error lineno and the source lineno. Searches in reverse from the backtrace lineno so we have a better chance of finding the correct line
The compiled template is likely to be longer than the source. Use the difference between the compiled and source sizes to determine the earliest line that could contain the highlight.
Parameters
-
compiledreq -
source_linesreq -
highlightreq -
error_linenoreq
Source
# File actionview/lib/action_view/template/handlers/erb.rb, line 119
def find_lineno_offset(compiled, source_lines, highlight, error_lineno)
first_index = error_lineno - 1 - compiled.size + source_lines.size
first_index = 0 if first_index < 0
last_index = error_lineno - 1
last_index = source_lines.size - 1 if last_index >= source_lines.size
last_index.downto(first_index) do |line_index|
next unless source_lines[line_index].include?(highlight)
return error_lineno - 1 - line_index
end
raise LocationParsingError, "Couldn't find code snippet"
end
Defined in actionview/lib/action_view/template/handlers/erb.rb line 119
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionView::Template::Handlers::ERB