class Root
Restricts coverage to a project root and converts paths relative to it.
Definitions
def initialize(output, path)
Initialize a root filter for the given path.
Signature
-
parameter
outputCovered::Base The output to wrap.
-
parameter
pathString The root path.
Implementation
def initialize(output, path)
super(output)
@path = path
end
attr :path
Signature
-
attribute
String The root path.
def expand_path(path)
Expand a path relative to this root.
Signature
-
parameter
pathString The path to expand.
-
returns
String The expanded path.
Implementation
def expand_path(path)
File.expand_path(super, @path)
end
def relative_path(path)
Convert a path under this root to a relative path.
Signature
-
parameter
pathString The path to relativize.
-
returns
String The relative path when under this root, otherwise the wrapped output result.
Implementation
def relative_path(path)
if path.start_with?(@path)
path.slice(@path.size+1, path.size)
else
super
end
end
def match?(path)
Whether the given path is under this root.
Signature
-
parameter
pathString The source path.
-
returns
Boolean Whether the path starts with this root.
Implementation
def match?(path)
path.start_with?(@path)
end