Class: EchoUploads::FilesystemStore
- Inherits:
-
AbstractStore
- Object
- AbstractStore
- EchoUploads::FilesystemStore
- Defined in:
- lib/echo_uploads/filesystem_store.rb
Instance Method Summary collapse
- #delete(key) ⇒ Object
- #exists?(key) ⇒ Boolean
- #open(key) ⇒ Object
- #path(key) ⇒ Object
- #read(key) ⇒ Object
- #write(key, file, metadata) ⇒ Object
Instance Method Details
#delete(key) ⇒ Object
3 4 5 6 |
# File 'lib/echo_uploads/filesystem_store.rb', line 3 def delete(key) _path = path(key) ::File.delete(_path) if ::File.exists?(_path) end |
#exists?(key) ⇒ Boolean
8 9 10 |
# File 'lib/echo_uploads/filesystem_store.rb', line 8 def exists?(key) ::File.exists? path(key) end |
#open(key) ⇒ Object
12 13 14 |
# File 'lib/echo_uploads/filesystem_store.rb', line 12 def open(key) ::File.open(path(key), 'rb', &block) end |
#path(key) ⇒ Object
16 17 18 |
# File 'lib/echo_uploads/filesystem_store.rb', line 16 def path(key) ::File.join folder, key end |
#read(key) ⇒ Object
20 21 22 |
# File 'lib/echo_uploads/filesystem_store.rb', line 20 def read(key) ::File.read path(key) end |
#write(key, file, metadata) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/echo_uploads/filesystem_store.rb', line 24 def write(key, file, ) _path = path key unless ::File.exists?(_path) unless ::File.exists?(folder) begin FileUtils.mkdir_p folder rescue Errno::EACCES raise "Permission denied trying to create #{folder}" end end FileUtils.cp file.path, _path end end |