class Byebug::SourceFileFormatter - byebug-11.0.1 Documentation

# 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 15
    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 67
    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 51
    def amend_final(line)
      amend(line, max_line)
    end

amend_initial(line) click to toggle source

    # File lib/byebug/source_file_formatter.rb, line 47
    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 20
    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 33
    def lines_around(center)
      lines(*range_around(center))
    end

max_initial_line() click to toggle source

    # File lib/byebug/source_file_formatter.rb, line 55
    def max_initial_line
      max_line - size + 1
    end

max_line() click to toggle source

    # File lib/byebug/source_file_formatter.rb, line 59
    def max_line
      @max_line ||= n_lines(file)
    end

range_around(center) click to toggle source

    # File lib/byebug/source_file_formatter.rb, line 37
    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 41
    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 63
    def size
      [Setting[:listsize], max_line].min
    end