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)


1090
1091
1092
1093
1094
# File 'sig/simplecov.rbs', line 1090

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)


1078
1079
1080
# File 'sig/simplecov.rbs', line 1078

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:



1097
1098
1099
# File 'sig/simplecov.rbs', line 1097

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

#missed?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/simplecov/source_file/method.rb', line 38

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)


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

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.



34
35
36
# File 'lib/simplecov/source_file/method.rb', line 34

def skipped!
  @skipped = true
end

#skipped?Boolean

Criterion-level skips (nocov chunks, # simplecov:disable / # simplecov:disable method regions) arrive via skipped! from MethodBuilder. Deliberately NOT derived from the lines' skip state: a line-only directive around a def must not remove the method from method totals. Without line info there is nothing to report against, so such a method stays skipped.

Returns:

  • (Boolean)


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

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

  @skipped = lines.empty?
end

#to_sString

Returns:

  • (String)


53
54
55
# File 'lib/simplecov/source_file/method.rb', line 53

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