Class: Rcov::CoverageInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/rcov.rb

Overview

Rcov::CoverageInfo is but a wrapper for an array, with some additional checks. It is returned by FileStatistics#coverage.

Instance Method Summary collapse

Constructor Details

#initialize(coverage_array) ⇒ CoverageInfo

Returns a new instance of CoverageInfo.



21
22
23
# File 'lib/rcov.rb', line 21

def initialize(coverage_array)
  @cover = coverage_array.clone
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *a, &b) ⇒ Object

:nodoc:



50
51
52
# File 'lib/rcov.rb', line 50

def method_missing(meth, *a, &b) # :nodoc:
  @cover.send(meth, *a, &b)
end

Instance Method Details

#[](line) ⇒ Object

Return the coverage status for the requested line. There are four possible return values:

  • nil if there’s no information for the requested line (i.e. it doesn’t exist)

  • true if the line was reported by Ruby as executed

  • :inferred if rcov inferred it was executed, despite not being reported by Ruby.

  • false otherwise, i.e. if it was not reported by Ruby and rcov’s heuristics indicated that it was not executed



33
34
35
# File 'lib/rcov.rb', line 33

def [](line)
  @cover[line]
end

#[]=(line, val) ⇒ Object

:nodoc:



37
38
39
40
41
42
43
# File 'lib/rcov.rb', line 37

def []=(line, val) # :nodoc:
  unless [true, false, :inferred].include? val
    raise RuntimeError, "What does #{val} mean?" 
  end
  return if line < 0 || line >= @cover.size
  @cover[line] = val
end

#to_aObject

Return an Array holding the code coverage information.



46
47
48
# File 'lib/rcov.rb', line 46

def to_a
  @cover.clone
end