class Files
Collects coverage information keyed by source path.
Definitions
def initialize(*)
Initialize an empty coverage collection.
Implementation
def initialize(*)
super
@paths = {}
end
attr_accessor :paths
Signature
-
attribute
Hash(String, Covered::Coverage) Coverage indexed by expanded source path.
def [](path)
Get or create coverage for the given path.
Signature
-
parameter
pathString The source path.
-
returns
Covered::Coverage The coverage object for the path.
Implementation
def [](path)
@paths[path] ||= Coverage.for(path)
end
def empty?
Whether there are no tracked paths.
Signature
-
returns
Boolean Whether no coverage paths are tracked.
Implementation
def empty?
@paths.empty?
end
def mark(path, line_number, value)
Mark a line in the given path as executed.
Signature
-
parameter
pathString The source path.
-
parameter
line_numberInteger The line number to mark.
-
parameter
valueInteger | Array(Integer) The execution count or counts to add.
Implementation
def mark(path, line_number, value)
self[path].mark(line_number, value)
end
def annotate(path, line_number, value)
Add an annotation to a line in the given path.
Signature
-
parameter
pathString The source path.
-
parameter
line_numberInteger The line number to annotate.
-
parameter
valueString The annotation text.
Implementation
def annotate(path, line_number, value)
self[path].annotate(line_number, value)
end
def add(coverage)
Merge coverage for the given path into this collection.
Signature
-
parameter
coverageCovered::Coverage The coverage object to merge.
Implementation
def add(coverage)
self[coverage.path].merge!(coverage)
end
def each
Enumerate tracked coverage objects.
Signature
-
yields
{|coverage| ...} Each tracked coverage object.
-
parameter
coverageCovered::Coverage The current coverage object.
-
parameter
-
returns
Enumerator | Nil An enumerator without a block.
Implementation
def each
return to_enum unless block_given?
@paths.each_value do |coverage|
yield coverage
end
end
def clear
Remove all tracked coverage data.
Signature
-
returns
Hash The cleared path map.
Implementation
def clear
@paths.clear
end