Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
trans opened this issue Jun 8, 2011 · 6 comments
Closed

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

trans opened this issue Jun 8, 2011 · 6 comments
Labels

Comments

@trans
Copy link
Contributor

trans commented Jun 8, 2011

How does one exclude a subdir from a group?

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

so to speak.

@colszowka
Copy link
Collaborator

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!

@trans
Copy link
Contributor Author

trans commented Jun 21, 2011

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 :)

@colszowka
Copy link
Collaborator

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') }

@trans
Copy link
Contributor Author

trans commented Jun 24, 2011

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 Jun 24, 2011
@colszowka
Copy link
Collaborator

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 :)

@bf4
Copy link
Collaborator

bf4 commented May 17, 2015

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

@bf4 bf4 closed this as completed May 17, 2015
@simplecov-ruby simplecov-ruby locked and limited conversation to collaborators May 17, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants