Class: Dragonfly::DataStorage::FileDataStore
- Defined in:
- lib/dragonfly/data_storage/file_data_store.rb
Instance Method Summary collapse
- #destroy(relative_path) ⇒ Object
- #disambiguate(path) ⇒ Object
- #retrieve(relative_path) ⇒ Object
- #store(temp_object, opts = {}) ⇒ Object
Instance Method Details
#destroy(relative_path) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/dragonfly/data_storage/file_data_store.rb', line 47 def destroy(relative_path) path = absolute(relative_path) FileUtils.rm path FileUtils.rm extra_data_path(path) purge_empty_directories(relative_path) rescue Errno::ENOENT => e raise DataNotFound, e. end |
#disambiguate(path) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/dragonfly/data_storage/file_data_store.rb', line 56 def disambiguate(path) dirname = File.dirname(path) basename = File.basename(path, '.*') extname = File.extname(path) "#{dirname}/#{basename}_#{Time.now.usec.to_s(32)}#{extname}" end |
#retrieve(relative_path) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/dragonfly/data_storage/file_data_store.rb', line 35 def retrieve(relative_path) path = absolute(relative_path) file = File.new(path) file.close [ file, retrieve_extra_data(path) ] rescue Errno::ENOENT => e raise DataNotFound, e. end |
#store(temp_object, opts = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/dragonfly/data_storage/file_data_store.rb', line 12 def store(temp_object, opts={}) relative_path = if opts[:path] opts[:path] else filename = temp_object.name || 'file' relative_path = relative_path_for(filename) end begin path = absolute(relative_path) until !File.exist?(path) path = disambiguate(path) end prepare_path(path) temp_object.to_file(path).close store_extra_data(path, temp_object) rescue Errno::EACCES => e raise UnableToStore, e. end relative(path) end |