class CallerWithContext::Location

Attributes

caller_location[R]
lines_of_context[R]

Public Class Methods

new(caller_location, lines_of_context=1) click to toggle source
# File lib/caller_with_context/location.rb, line 5
def initialize(caller_location, lines_of_context=1)
  @caller_location  = caller_location
  @lines_of_context = lines_of_context
end

Public Instance Methods

context_lines() click to toggle source
# File lib/caller_with_context/location.rb, line 10
def context_lines
  line_indexes.each.map {|line_number| lines_in_file[line_number]&.chomp }
end
line_indexes(lineno=caller_location.lineno-lines_of_context) click to toggle source
# File lib/caller_with_context/location.rb, line 14
def line_indexes(lineno=caller_location.lineno-lines_of_context)
  min = lineno < lines_of_context ? 0 : lineno - lines_of_context
  max = lineno >= lines_in_file.count ? lines_in_file.count : lineno + lines_of_context
  min..max
end
lines_in_file() click to toggle source
# File lib/caller_with_context/location.rb, line 20
def lines_in_file
  @lines_in_file ||= File.readlines caller_location.absolute_path
end
to_s() click to toggle source
# File lib/caller_with_context/location.rb, line 24
def to_s
  caller_location.to_s
end