Class: SimpleCov::SourceFile::Method

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

Overview

Represents a single method detected in coverage data. Provides helpers similar to Branch for coverage status.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_file, info, coverage) ⇒ Method

Returns a new instance of Method.



11
12
13
14
15
# File 'lib/simplecov/source_file/method.rb', line 11

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_nameObject (readonly)

Returns the value of attribute class_name.



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

def class_name
  @class_name
end

#coverageObject (readonly)

Returns the value of attribute coverage.



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

def coverage
  @coverage
end

#end_colObject (readonly)

Returns the value of attribute end_col.



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

def end_col
  @end_col
end

#end_lineObject (readonly)

Returns the value of attribute end_line.



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

def end_line
  @end_line
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



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

def method_name
  @method_name
end

#source_fileObject (readonly)

Returns the value of attribute source_file.



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

def source_file
  @source_file
end

#start_colObject (readonly)

Returns the value of attribute start_col.



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

def start_col
  @start_col
end

#start_lineObject (readonly)

Returns the value of attribute start_line.



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

#linesObject



36
37
38
# File 'lib/simplecov/source_file/method.rb', line 36

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.

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!Object

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_sObject



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

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