Class: GDSync::LocalFileSystem::File
- Inherits:
-
AbstractFile
- Object
- AbstractFile
- GDSync::LocalFileSystem::File
- Defined in:
- lib/file_system/local_file_system.rb
Instance Method Summary collapse
- #birthtime ⇒ Object
- #copy_to(_dest_dir, _birthtime, _mtime) ⇒ Object
- #create_read_io ⇒ Object
- #delete! ⇒ Object
- #fs ⇒ Object
-
#initialize(fs, path) ⇒ File
constructor
A new instance of File.
- #md5 ⇒ Object
- #mtime ⇒ Object
- #path ⇒ Object
- #size ⇒ Object
- #title ⇒ Object
- #update!(read_io, _mtime) ⇒ Object
- #write_to(write_io) ⇒ Object
Constructor Details
#initialize(fs, path) ⇒ File
13 14 15 16 17 |
# File 'lib/file_system/local_file_system.rb', line 13 def initialize(fs, path) @fs = fs @path = path @md5 = nil end |
Instance Method Details
#birthtime ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/file_system/local_file_system.rb', line 77 def birthtime f = ::File.new(@path) begin f.birthtime.to_datetime rescue NotImplementedError => e f.mtime.to_datetime end end |
#copy_to(_dest_dir, _birthtime, _mtime) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/file_system/local_file_system.rb', line 53 def copy_to(_dest_dir, _birthtime, _mtime) file, io = _dest_dir.create_write_io!(title) write_to(io) io.close ::File.utime(_mtime.to_time, _mtime.to_time, file.path) file end |
#create_read_io ⇒ Object
43 44 45 |
# File 'lib/file_system/local_file_system.rb', line 43 def create_read_io open(@path, 'rb') end |
#delete! ⇒ Object
69 70 71 |
# File 'lib/file_system/local_file_system.rb', line 69 def delete! ::File.delete(@path) end |
#fs ⇒ Object
39 40 41 |
# File 'lib/file_system/local_file_system.rb', line 39 def fs @fs end |
#md5 ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/file_system/local_file_system.rb', line 31 def md5 if @md5.nil? @md5 = ::Digest::MD5.file(@path).to_s end @md5 end |
#mtime ⇒ Object
27 28 29 |
# File 'lib/file_system/local_file_system.rb', line 27 def mtime ::File.mtime(@path).to_datetime end |
#path ⇒ Object
73 74 75 |
# File 'lib/file_system/local_file_system.rb', line 73 def path @path end |
#size ⇒ Object
23 24 25 |
# File 'lib/file_system/local_file_system.rb', line 23 def size ::File.size(@path) end |
#title ⇒ Object
19 20 21 |
# File 'lib/file_system/local_file_system.rb', line 19 def title ::File.basename(@path) end |
#update!(read_io, _mtime) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/file_system/local_file_system.rb', line 62 def update!(read_io, _mtime) open(@path, 'wb') { |f| ::IO.copy_stream(read_io, f) } ::File.utime(_mtime.to_time, _mtime.to_time, @path) end |
#write_to(write_io) ⇒ Object
47 48 49 50 51 |
# File 'lib/file_system/local_file_system.rb', line 47 def write_to(write_io) open(@path, 'rb') { |f| ::IO.copy_stream(f, write_io) } end |