Class: SimpleCov::SourceFile::Method

Inherits:
Object
  • Object
show all
Defined in:
lib/simplecov/source_file/method.rb,
sig/simplecov.rbs

Overview

A single method detected in the coverage data.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_file, info, coverage) ⇒ Method

info is the Coverage method key minus its class entry: [class_name, method_name, start_line, start_col, end_line, end_col].

Parameters:

  • source_file (SourceFile)
  • info ([ Module | String, Symbol | String, Integer?, Integer?, Integer?, Integer? ])
  • coverage (Integer)


1033
1034
1035
1036
1037
# File 'sig/simplecov.rbs', line 1033

def initialize(source_file, info, coverage)
  @source_file = source_file
  @class_name, @method_name, @start_line, @start_col, @end_line, @end_col = info
  @coverage = coverage
end

Instance Attribute Details

#class_nameModule, String (readonly)

A Module when the data comes straight from Coverage, a String after a JSON round-trip through a resultset.

Returns:

  • (Module, String)


1021
1022
1023
# File 'sig/simplecov.rbs', line 1021

def class_name
  @class_name
end

#coverageInteger (readonly)

Returns the value of attribute coverage.

Returns:

  • (Integer)


8
9
10
# File 'lib/simplecov/source_file/method.rb', line 8

def coverage
  @coverage
end

#end_colInteger? (readonly)

Returns the value of attribute end_col.

Returns:

  • (Integer, nil)


8
9
10
# File 'lib/simplecov/source_file/method.rb', line 8

def end_col
  @end_col
end

#end_lineInteger? (readonly)

Returns the value of attribute end_line.

Returns:

  • (Integer, nil)


8
9
10
# File 'lib/simplecov/source_file/method.rb', line 8

def end_line
  @end_line
end

#method_nameSymbol, String (readonly)

Returns the value of attribute method_name.

Returns:

  • (Symbol, String)


8
9
10
# File 'lib/simplecov/source_file/method.rb', line 8

def method_name
  @method_name
end

#source_fileSourceFile (readonly)

Returns the value of attribute source_file.

Returns:



8
9
10
# File 'lib/simplecov/source_file/method.rb', line 8

def source_file
  @source_file
end

#start_colInteger? (readonly)

Returns the value of attribute start_col.

Returns:

  • (Integer, nil)


8
9
10
# File 'lib/simplecov/source_file/method.rb', line 8

def start_col
  @start_col
end

#start_lineInteger? (readonly)

Returns the value of attribute start_line.

Returns:

  • (Integer, nil)


8
9
10
# File 'lib/simplecov/source_file/method.rb', line 8

def start_line
  @start_line
end

Instance Method Details

#covered?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/simplecov/source_file/method.rb', line 17

def covered?
  !skipped? && coverage.positive?
end

#linesArray[Line]

The source lines spanned by this method ([] when the location is unknown).

Returns:



1040
1041
1042
# File 'sig/simplecov.rbs', line 1040

def lines
  @lines ||= start_line && end_line ? source_file.lines[(start_line - 1)..(end_line - 1)] || [] : []
end

#missed?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/simplecov/source_file/method.rb', line 32

def missed?
  !skipped? && coverage.zero?
end

#overlaps_with?(line_range) ⇒ Boolean

Whether this method's source range intersects the given inclusive line range.

Parameters:

  • line_range (Range[Integer])

Returns:

  • (Boolean)


41
42
43
44
45
# File 'lib/simplecov/source_file/method.rb', line 41

def overlaps_with?(line_range)
  return false unless start_line && end_line

  start_line <= line_range.end && end_line >= line_range.begin
end

#skipped!void

This method returns an undefined value.

Flag the method as skipped directly, without going through its lines.



28
29
30
# File 'lib/simplecov/source_file/method.rb', line 28

def skipped!
  @skipped = true
end

#skipped?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
# File 'lib/simplecov/source_file/method.rb', line 21

def skipped?
  return @skipped if defined?(@skipped)

  @skipped = lines.all?(&:skipped?)
end

#to_sString

Returns:

  • (String)


47
48
49
# File 'lib/simplecov/source_file/method.rb', line 47

def to_s
  "#{class_name}##{method_name}"
end