Module: Temppath
- Defined in:
- lib/temppath.rb,
lib/temppath/version.rb
Overview
Temppath creates temporary 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.
Defined Under Namespace
Modules: OriginalMethodHolder, SecurePermissionMethods
Constant Summary collapse
- VERSION =
version of temppath gem
"0.2.0"
Class Attribute Summary collapse
-
.basedir ⇒ Pathname
readonly
Defalut base directory for paths created by Temppath.
-
.unlink ⇒ Boolean
True if unlink mode is enabled.
Class Method Summary collapse
-
.create(option = {}) ⇒ Object
Create a temporary path.
-
.mkdir(option = {}) ⇒ Object
Create a temporary directory.
-
.remove_basedir ⇒ void
Remove current temporary directory.
-
.touch(option = {}) ⇒ Object
Create a empty file.
-
.update_basedir ⇒ Pathname
Remove current base directory, create a new base directory, and use it.
Class Attribute Details
.basedir ⇒ Pathname (readonly)
Returns defalut base directory for paths created by Temppath.
78 79 80 |
# File 'lib/temppath.rb', line 78 def basedir @basedir end |
.unlink ⇒ Boolean
Returns true if unlink mode is enabled.
82 83 84 |
# File 'lib/temppath.rb', line 82 def unlink @unlink end |
Class Method Details
.create(option = {}) ⇒ Object
Create a temporary path. This method creates no files.
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/temppath.rb', line 91 def create(option={}) basename = option[:basename] || "" _basedir = option[:basedir] || basedir path = Pathname.new(_basedir) + (basename.to_s + generate_uuid) path.extend OriginalMethodHolder path.extend SecurePermissionMethods if _basedir != basedir Kernel.at_exit {FileUtils.remove_entry_secure(path) rescue Errno::ENOENT} end return path end |
.mkdir(option = {}) ⇒ Object
Create a temporary directory.
104 105 106 107 108 109 |
# File 'lib/temppath.rb', line 104 def mkdir(option={}) mode = option[:mode] || 0700 path = create(option) path.mkdir(mode) return path end |
.remove_basedir ⇒ void
This method returns an undefined value.
Remove current temporary directory.
132 133 134 |
# File 'lib/temppath.rb', line 132 def remove_basedir FileUtils.remove_entry_secure(@basedir) if @basedir.exist? end |
.touch(option = {}) ⇒ Object
Create a empty file.
112 113 114 115 116 117 |
# File 'lib/temppath.rb', line 112 def touch(option={}) mode = option[:mode] || 0600 path = create(option) path.open("w", mode) return path end |
.update_basedir ⇒ Pathname
Remove current base directory, create a new base directory, and use it.
124 125 126 127 |
# File 'lib/temppath.rb', line 124 def update_basedir remove_basedir @basedir = create_basedir end |