class Storage::FilesystemStore
Public Class Methods
new(path_prefix, options={})
click to toggle source
# File lib/storage/filesystem_store.rb, line 3 def initialize(path_prefix, options={}) @dir = options[:root_path] || raise('Must define root path for file system store') @path_prefix = path_prefix FileUtils.mkdir_p File.join(@dir, @path_prefix) end
Public Instance Methods
absolute_path(*relative_paths)
click to toggle source
todo: this should be interface that retrive a lazy file object
# File lib/storage/filesystem_store.rb, line 31 def absolute_path(*relative_paths) File.join(@dir, @path_prefix, *relative_paths) end
clear()
click to toggle source
# File lib/storage/filesystem_store.rb, line 43 def clear FileUtils.rm_rf File.join(@dir, @path_prefix) end
copy(path, to_local_path)
click to toggle source
# 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)
click to toggle source
# File lib/storage/filesystem_store.rb, line 39 def delete(path) FileUtils.rm_rf(absolute_path(path)) end
exists?(path)
click to toggle source
# File lib/storage/filesystem_store.rb, line 35 def exists?(path) File.exists?(absolute_path(path)) end
read(path)
click to toggle source
# File lib/storage/filesystem_store.rb, line 14 def read(path) File.read(absolute_path(path)) end
upload(path, local_file)
click to toggle source
# 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)
click to toggle source
# 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