Class: Storage::FilesystemStore
- Inherits:
-
Object
- Object
- Storage::FilesystemStore
- Defined in:
- lib/storage/filesystem_store.rb
Instance Method Summary collapse
-
#absolute_path(*relative_paths) ⇒ Object
todo: this should be interface that retrive a lazy file object.
- #clear ⇒ Object
- #copy(path, to_local_path) ⇒ Object
- #delete(path) ⇒ Object
- #exists?(path) ⇒ Boolean
-
#initialize(path_prefix, options = {}) ⇒ FilesystemStore
constructor
A new instance of FilesystemStore.
- #read(path) ⇒ Object
- #upload(path, local_file) ⇒ Object
- #upload_dir(path, local_dir) ⇒ Object
Constructor Details
#initialize(path_prefix, options = {}) ⇒ FilesystemStore
Returns a new instance of FilesystemStore.
3 4 5 6 7 |
# File 'lib/storage/filesystem_store.rb', line 3 def initialize(path_prefix, ={}) @dir = [:root_path] || raise('Must define root path for file system store') @path_prefix = path_prefix FileUtils.mkdir_p File.join(@dir, @path_prefix) end |
Instance Method Details
#absolute_path(*relative_paths) ⇒ Object
todo: this should be interface that retrive a lazy file object
31 32 33 |
# File 'lib/storage/filesystem_store.rb', line 31 def absolute_path(*relative_paths) File.join(@dir, @path_prefix, *relative_paths) end |
#clear ⇒ Object
43 44 45 |
# File 'lib/storage/filesystem_store.rb', line 43 def clear FileUtils.rm_rf File.join(@dir, @path_prefix) end |
#copy(path, to_local_path) ⇒ Object
9 10 11 12 |
# File 'lib/storage/filesystem_store.rb', line 9 def copy(path, to_local_path) raise "File(#{path}) does not exist" unless File.exists?(absolute_path(path)) FileUtils.cp(absolute_path(path), to_local_path) end |
#delete(path) ⇒ Object
39 40 41 |
# File 'lib/storage/filesystem_store.rb', line 39 def delete(path) FileUtils.rm_rf(absolute_path(path)) end |
#exists?(path) ⇒ Boolean
35 36 37 |
# File 'lib/storage/filesystem_store.rb', line 35 def exists?(path) File.exists?(absolute_path(path)) end |
#read(path) ⇒ Object
14 15 16 |
# File 'lib/storage/filesystem_store.rb', line 14 def read(path) File.read(absolute_path(path)) end |
#upload(path, local_file) ⇒ Object
18 19 20 21 |
# File 'lib/storage/filesystem_store.rb', line 18 def upload(path, local_file) FileUtils.mkdir_p(absolute_path(path)) FileUtils.mv(local_file, absolute_path(path)) end |
#upload_dir(path, local_dir) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/storage/filesystem_store.rb', line 23 def upload_dir(path, local_dir) FileUtils.rm_rf(absolute_path(path)) Dir[File.join(local_dir, "*")].each do |f| upload(path, f) end end |