Class: Minitest::Heat::Backtrace::LineCount

Inherits:
Object
  • Object
show all
Defined in:
lib/minitest/heat/backtrace/line_count.rb

Overview

Determines an optimal line count for backtrace locations in order to have relevant

information but keep the backtrace as compact as possible

Constant Summary collapse

DEFAULT_LINE_COUNT =
20

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locations) ⇒ LineCount

Returns a new instance of LineCount.



13
14
15
# File 'lib/minitest/heat/backtrace/line_count.rb', line 13

def initialize(locations)
  @locations = locations
end

Instance Attribute Details

#locationsObject

Returns the value of attribute locations.



11
12
13
# File 'lib/minitest/heat/backtrace/line_count.rb', line 11

def locations
  @locations
end

Instance Method Details

#earliest_project_locationObject



17
18
19
# File 'lib/minitest/heat/backtrace/line_count.rb', line 17

def earliest_project_location
  locations.rindex(&:project_file?)
end

#limitObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/minitest/heat/backtrace/line_count.rb', line 25

def limit
  return 0 if locations.empty?

  # Find the minimum relevant index, then add 1 to convert from index to count
  [
    DEFAULT_LINE_COUNT - 1,
    earliest_project_location,
    max_location
  ].compact.min + 1
end

#max_locationObject



21
22
23
# File 'lib/minitest/heat/backtrace/line_count.rb', line 21

def max_location
  [locations.size - 1, 0].max
end