class Byebug::SourceFileFormatter

Formats specific line ranges in a source file

Attributes

annotator[R]
file[R]

Public Class Methods

new(file, annotator) click to toggle source
# File lib/byebug/source_file_formatter.rb, line 14
def initialize(file, annotator)
  @file = file
  @annotator = annotator
end

Public Instance Methods

amend(line, ceiling) click to toggle source
# File lib/byebug/source_file_formatter.rb, line 66
def amend(line, ceiling)
  [ceiling, [1, line].max].min
end
amend_final(line) click to toggle source
# File lib/byebug/source_file_formatter.rb, line 50
def amend_final(line)
  amend(line, max_line)
end
amend_initial(line) click to toggle source
# File lib/byebug/source_file_formatter.rb, line 46
def amend_initial(line)
  amend(line, max_initial_line)
end
lines(min, max) click to toggle source
# File lib/byebug/source_file_formatter.rb, line 19
def lines(min, max)
  File.foreach(file).with_index.map do |line, lineno|
    next unless (min..max).cover?(lineno + 1)

    format(
      "%<annotation>s %<lineno>#{max.to_s.size}d: %<source>s",
      annotation: annotator.call(lineno + 1),
      lineno: lineno + 1,
      source: line
    )
  end
end
lines_around(center) click to toggle source
# File lib/byebug/source_file_formatter.rb, line 32
def lines_around(center)
  lines(*range_around(center))
end
max_initial_line() click to toggle source
# File lib/byebug/source_file_formatter.rb, line 54
def max_initial_line
  max_line - size + 1
end
max_line() click to toggle source
# File lib/byebug/source_file_formatter.rb, line 58
def max_line
  @max_line ||= n_lines(file)
end
range_around(center) click to toggle source
# File lib/byebug/source_file_formatter.rb, line 36
def range_around(center)
  range_from(center - size / 2)
end
range_from(min) click to toggle source
# File lib/byebug/source_file_formatter.rb, line 40
def range_from(min)
  first = amend_initial(min)

  [first, first + size - 1]
end
size() click to toggle source
# File lib/byebug/source_file_formatter.rb, line 62
def size
  [Setting[:listsize], max_line].min
end