Class: SimpleCov::SourceFile::Method

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_file, info, coverage) ⇒ Method

Returns a new instance of Method.

Parameters:



9
10
11
12
13
# File 'lib/simplecov/source_file/method.rb', line 9

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)

Returns the value of attribute class_name.

Returns:



6
7
8
# File 'lib/simplecov/source_file/method.rb', line 6

def class_name
  @class_name
end

#coverageInteger (readonly)

Returns the value of attribute coverage.

Returns:



6
7
8
# File 'lib/simplecov/source_file/method.rb', line 6

def coverage
  @coverage
end

#end_colInteger? (readonly)

Returns the value of attribute end_col.

Returns:



6
7
8
# File 'lib/simplecov/source_file/method.rb', line 6

def end_col
  @end_col
end

#end_lineInteger? (readonly)

Returns the value of attribute end_line.

Returns:



6
7
8
# File 'lib/simplecov/source_file/method.rb', line 6

def end_line
  @end_line
end

#method_nameSymbol, String (readonly)

Returns the value of attribute method_name.

Returns:



6
7
8
# File 'lib/simplecov/source_file/method.rb', line 6

def method_name
  @method_name
end

#source_fileSourceFile (readonly)

Returns the value of attribute source_file.

Returns:



6
7
8
# File 'lib/simplecov/source_file/method.rb', line 6

def source_file
  @source_file
end

#start_colInteger? (readonly)

Returns the value of attribute start_col.

Returns:



6
7
8
# File 'lib/simplecov/source_file/method.rb', line 6

def start_col
  @start_col
end

#start_lineInteger? (readonly)

Returns the value of attribute start_line.

Returns:



6
7
8
# File 'lib/simplecov/source_file/method.rb', line 6

def start_line
  @start_line
end

Instance Method Details

#covered?Boolean

Returns:



15
16
17
# File 'lib/simplecov/source_file/method.rb', line 15

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

#linesArray[Line]

Returns:



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

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

#missed?Boolean

Returns:



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

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

#overlaps_with?(line_range) ⇒ Boolean

Parameters:

Returns:



43
44
45
46
47
# File 'lib/simplecov/source_file/method.rb', line 43

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.



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

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:



25
26
27
28
29
# File 'lib/simplecov/source_file/method.rb', line 25

def skipped?
  return @skipped if instance_variable_defined?(:@skipped)

  @skipped = lines.empty?
end

#to_sString

Returns:



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

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