Class: Covered::Root
Overview
Restricts coverage to a project root and converts paths relative to it.
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
- #The root path.(rootpath.) ⇒ Object readonly
Attributes inherited from Wrapper
Instance Method Summary collapse
-
#expand_path(path) ⇒ Object
Expand a path relative to this root.
-
#initialize(output, path) ⇒ Root
constructor
Initialize a root filter for the given path.
-
#match?(path) ⇒ Boolean
Whether the given path is under this root.
-
#relative_path(path) ⇒ Object
Convert a path under this root to a relative path.
Methods inherited from Filter
Methods inherited from Wrapper
#accept?, #add, #clear, #each, #finish, #mark, #start, #to_h
Methods inherited from Base
#accept?, #add, #clear, #each, #finish, #mark, #start
Constructor Details
#initialize(output, path) ⇒ Root
Initialize a root filter for the given path.
181 182 183 184 185 |
# File 'lib/covered/files.rb', line 181 def initialize(output, path) super(output) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
188 189 190 |
# File 'lib/covered/files.rb', line 188 def path @path end |
#The root path.(rootpath.) ⇒ Object (readonly)
188 |
# File 'lib/covered/files.rb', line 188 attr :path |
Instance Method Details
#expand_path(path) ⇒ Object
Expand a path relative to this root.
193 194 195 |
# File 'lib/covered/files.rb', line 193 def (path) File.(super, @path) end |
#match?(path) ⇒ Boolean
Whether the given path is under this root.
211 212 213 |
# File 'lib/covered/files.rb', line 211 def match?(path) path.start_with?(@path) end |
#relative_path(path) ⇒ Object
Convert a path under this root to a relative path.
200 201 202 203 204 205 206 |
# File 'lib/covered/files.rb', line 200 def relative_path(path) if path.start_with?(@path) path.slice(@path.size+1, path.size) else super end end |