Temppath
Temppath is a Ruby library for generating temporary file path. The differences from standard tempfile.rb are that this library generates Pathname objects with no files and filenames are based on UUID. Files in paths generated by this are deleted when Ruby exits.
Features
- You can generate a path without file.
- Temppath can generate files and directories as well. Therefore you are free from confusion which is correct tmpfile/tempfile or tmpdir/tempdir.
- Generated paths are
Pathname
objects.
Installation
$ gem install temppath
Usage
Create a path
path = Temppath.create
#=> #<Pathname:/tmp/ruby-temppath-20130407-5775-w5k77l/f41bd6c5-fc99-4b7a-8f68-95b7ae4a6b22>
path.exist? #=> false
path.open("w")
"%o" % path.stat.mode #=> "100600" (default permission 0600)
Create a directory
path = Temppath.mkdir
path.exist? #=> true
path.directory? #=> true
"%o" % path.stat.mode #=> "40700"
Create an empty file
path = Temppath.touch
path.exist? #=> true
path.file? #=> true
"%o" % path.stat.mode #=> "100600"
Use temporary path generator
You can use Temppath::Generator
when you want to use multiple base
directory. Generated paths have same natures as paths from Tempath.create
,
mkdir
, and touch
.
# make a generator
temppath = Temppath::Generator.new("/tmp/other-dir")
path = temppath.create
path.exist? #=> false
path.open("w")
"%o" % path.stat.mode #=> "100600"
path = temppath.mkdir
path.exist? #=> true
path.directory? #=> true
"%o" % path.stat.mode #=> "40700"
path = temppath.touch
path.exist? #=> true
path.file? #=> true
"%o" % path.stat.mode #=> "100600"
Documentation
License
Temppath is free software distributed under MIT license.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request