Skip to content


How to exclude a subdir from groups target directory? #53

trans opened this Issue · 6 comments

3 participants


How does one exclude a subdir from a group?

add_group "Foo", "lib/foo" - "lib/foo/bar"

so to speak.


Hey, may I humbly suggest to RTFM :)

Under the Groups section of the Readme there's an explanation on how to define groups. You can do that by supplying a block as well, which will then yield each source file (check the rdoc on the public api of that) to that block, so you could check the path of the file and reject all those that are in your subdirectory.

Hope this helps!

@colszowka colszowka closed this

I did RTFM. And I know about the block and it's seems to me a rather inefficient approach. I was hoping there might be a better way and if not, I would suggest that there should be.

May I humbly suggest you refrain from using RTFM as an answer :)


Oh, sorry, since you did not mention the block syntax for group definition, I figured you missed out on it :)

Unfortunately, adding your proposed syntax would require SimpleCov to extend/monkey patch Ruby's String literals to be aware of Path names and also to add the "-" method to String which, even though this method does not exist in MRI right now, would be a very bad practice IMHO since it is a very low-level method name and might be added in future Ruby versions to Strings.

What would be possible would be to create a Subclass for String that has those features, which would result in something like

add_group "Foo", SrcPath('lib/foo') - SrcPath('lib/foo/bar')

I think this looks rather clumsy though and adds unneccessary complexity through obscurity, since the block version might be almost the same, though in a bit more expressive way:

add_group("Foo") {|src| src.filename.include?('lib/foo') and not src.filename.include?('lib/foo/bar') }

Thanks. Actually I should have peaked at the code a bit more myself. I assumed that the "filter" argument was doing some sort of Dir.glob to segment things. I see now that every path is just going through a selection block in the end. So your block solution is no less efficient. (Is my analysis right?)

It also means that File.fnmatch? syntax can't be used in the filter. Didn't realize that.

Note though you could do:

add_group(group_name, filter_argument=nil, options={}, &filter_proc)

Allowing something like:

add_group "Foo", 'lib/foo', :omit => 'lib/foo/bar'

Or you could take it even further to handle fnmatch globs too:

add_group "FooS", :glob => 'lib/foo/s*.rb'

Food for thought. Thanks again.

@colszowka colszowka reopened this

Yeah, makes sense - maybe this should get refactored to use Ruby's built-in path functionalities like you mentioned. Reopening this as a reminder to investigate :)


Closing as stale. Please reopen if this is still an issue. (And take a look at #340 )

@bf4 bf4 closed this
@bf4 bf4 locked and limited conversation to collaborators
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Something went wrong with that request. Please try again.