Class: IOStreams::File::Path
- Defined in:
- lib/io_streams/file/path.rb
Instance Attribute Summary
Attributes inherited from BasePath
Class Method Summary collapse
-
.mkpath(path) ⇒ Object
Used by writers that can write directly to file to create the target path.
-
.temp_file_name(basename, extension = '') ⇒ Object
Yields the path to a temporary file_name.
Instance Method Summary collapse
- #delete(recursively: false) ⇒ Object
- #exist? ⇒ Boolean
- #mkdir ⇒ Object
- #mkpath ⇒ Object
- #size ⇒ Object
Methods inherited from BasePath
#initialize, #join, #reader, #to_s, #writer
Constructor Details
This class inherits a constructor from IOStreams::BasePath
Class Method Details
.mkpath(path) ⇒ Object
Used by writers that can write directly to file to create the target path
23 24 25 26 |
# File 'lib/io_streams/file/path.rb', line 23 def self.mkpath(path) dir = ::File.dirname(path) FileUtils.mkdir_p(dir) unless ::File.exist?(dir) end |
.temp_file_name(basename, extension = '') ⇒ Object
Yields the path to a temporary file_name.
File is deleted upon completion if present.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/io_streams/file/path.rb', line 10 def self.temp_file_name(basename, extension = '') result = nil ::Dir::Tmpname.create([basename, extension]) do |tmpname| begin result = yield(tmpname) ensure ::File.unlink(tmpname) if ::File.exist?(tmpname) end end result end |
Instance Method Details
#delete(recursively: false) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/io_streams/file/path.rb', line 46 def delete(recursively: false) return self unless ::File.exist?(path) if ::File.directory?(path) recursively ? FileUtils.remove_dir(path) : Dir.delete(path) else ::File.unlink(path) end self end |
#exist? ⇒ Boolean
38 39 40 |
# File 'lib/io_streams/file/path.rb', line 38 def exist? ::File.exist?(path) end |
#mkdir ⇒ Object
33 34 35 36 |
# File 'lib/io_streams/file/path.rb', line 33 def mkdir FileUtils.mkdir_p(path) unless ::File.exist?(path) self end |
#mkpath ⇒ Object
28 29 30 31 |
# File 'lib/io_streams/file/path.rb', line 28 def mkpath self.class.mkpath(path) self end |
#size ⇒ Object
42 43 44 |
# File 'lib/io_streams/file/path.rb', line 42 def size ::File.size(path) end |