-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add Tempfile.tempname accepting block #5937
Add Tempfile.tempname accepting block #5937
Conversation
bbf9700
to
503a191
Compare
#4096 is similar but explicitly for directories and creates a directory at the path. |
Awesome! I should have thought about this when I initially added |
That's weird: I'm asking for a String but suddenly the methods deletes a file or directory on disk? Requiring It's a good snippet to put into test helpers, but I'm not sure this should be pushed to stdlib... |
I second @ysbaddaden here, concept itself might be useful enough to add it as a new method, or feature behind an argument (sth like |
So you'r basically objecting the name, not the concept? I see the point of confusion, but on the other hand it just follows a common idiom in Crystal, to have a yielding method overload which adds some cleanup to the non-yielding behaviour. @ysbaddaden Removing a directory recursively should either be implemented outside |
The core problem is that we're yielding a The core problem with this PR is that it has to work within the confines of Crystal's existing conflation of paths and strings, which is why I'm ok with this PR. We'll fix up this PR when we merge #5550. This PR also shows exactly why |
I object. Such behaviour would be more fitting for a |
This pull request isn't ahead of its time, it should just be a method in spec. If it happens to be very useful across many projects, then maybe we could consider moving this to stdlib, otherwise let's not bother. With a proper stdlib it's just a few lines to write anyway. Let's fix things in the right order, instead of adding new features on a whim. Recursive deletion is indeed important: let's work on that! Forget about Tempfile and FileUtils and work on Path, rework Dir and File, so they become so good that maybe we'll just drop Tempfile and FileUtils in the end. |
I'm closing this. Since #5951 solved the most important use case in specs, but I still think this would also be useful as a method outside of specs. Maybe there will be a new PR at some point... |
This PR adds an overload to
Tempfile.tempname
which yields the path and ensures it is cleaned up after exiting the block.A possible use case is detailed in #5811
Followup on #5360