Class: Milton::Storage::DiskFile
- Inherits:
-
StoredFile
- Object
- StoredFile
- Milton::Storage::DiskFile
- Defined in:
- lib/milton/storage/disk_file.rb
Overview
How Milton deals with a file stored on disk…
Instance Attribute Summary
Attributes inherited from StoredFile
Class Method Summary collapse
-
.recreate_directory(directory, options) ⇒ Object
Creates the given directory and sets it to the mode given in options.
Instance Method Summary collapse
-
#copy(destination) ⇒ Object
Copies this file to the given location on disk.
-
#destroy ⇒ Object
Removes the file from the underlying file system and any derivatives of the file.
-
#dirname ⇒ Object
Returns the full directory path up to the file, w/o the filename.
-
#exists? ⇒ Boolean
Returns true if the file exists on the underlying file system.
-
#mime_type ⇒ Object
Returns the mime type of the file.
-
#path ⇒ Object
Returns the full path and filename to the file with the given options.
-
#store(source) ⇒ Object
Writes the given source file to this file’s path.
Methods inherited from StoredFile
adapter, #clone, create, #initialize, sanitize_filename
Constructor Details
This class inherits a constructor from Milton::Storage::StoredFile
Class Method Details
.recreate_directory(directory, options) ⇒ Object
Creates the given directory and sets it to the mode given in options
10 11 12 13 14 |
# File 'lib/milton/storage/disk_file.rb', line 10 def recreate_directory(directory, ) return true if File.exists?(directory) FileUtils.mkdir_p(directory) File.chmod([:storage_options][:chmod], directory) end |
Instance Method Details
#copy(destination) ⇒ Object
Copies this file to the given location on disk.
50 51 52 53 |
# File 'lib/milton/storage/disk_file.rb', line 50 def copy(destination) Milton.log "copying #{path} to #{destination}" FileUtils.cp(path, destination) end |
#destroy ⇒ Object
Removes the file from the underlying file system and any derivatives of the file.
44 45 46 47 |
# File 'lib/milton/storage/disk_file.rb', line 44 def destroy Milton.log "destroying path #{dirname}" FileUtils.rm_rf dirname if File.exists?(dirname) end |
#dirname ⇒ Object
Returns the full directory path up to the file, w/o the filename.
25 26 27 |
# File 'lib/milton/storage/disk_file.rb', line 25 def dirname File.join(root_path, partitioned_path) end |
#exists? ⇒ Boolean
Returns true if the file exists on the underlying file system.
30 31 32 |
# File 'lib/milton/storage/disk_file.rb', line 30 def exists? File.exist?(path) end |
#mime_type ⇒ Object
Returns the mime type of the file.
56 57 58 |
# File 'lib/milton/storage/disk_file.rb', line 56 def mime_type Milton.syscall("file -Ib #{path}").gsub(/\n/,"") end |
#path ⇒ Object
Returns the full path and filename to the file with the given options. If no options are given then returns the path and filename to the original file.
20 21 22 |
# File 'lib/milton/storage/disk_file.rb', line 20 def path File.join(dirname, filename) end |
#store(source) ⇒ Object
Writes the given source file to this file’s path.
35 36 37 38 39 40 |
# File 'lib/milton/storage/disk_file.rb', line 35 def store(source) Milton.log "storing #{source} to disk at #{path}" self.class.recreate_directory(dirname, ) File.cp(source, path) File.chmod([:storage_options][:chmod], path) end |