class EchoUploads::FilesystemStore

Public Instance Methods

delete(key) click to toggle source
# 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) click to toggle source
# File lib/echo_uploads/filesystem_store.rb, line 8
def exists?(key)
  ::File.exists? path(key)
end
open(key) click to toggle source
# File lib/echo_uploads/filesystem_store.rb, line 12
def open(key)
  ::File.open(path(key), 'rb', &block)
end
path(key) click to toggle source
# File lib/echo_uploads/filesystem_store.rb, line 16
def path(key)
  ::File.join folder, key
end
read(key) click to toggle source
# File lib/echo_uploads/filesystem_store.rb, line 20
def read(key)
  ::File.read path(key)
end
write(key, file, metadata) click to toggle source
# File lib/echo_uploads/filesystem_store.rb, line 24
def write(key, file, metadata)
  _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

Private Instance Methods

folder() click to toggle source

Can be customized in your per-environment config like this:

config.echo_uploads.folder = File.join(Rails.root, 'my_uploads_folder', 'development')
# File lib/echo_uploads/filesystem_store.rb, line 42
def folder
  if Rails.configuration.respond_to?(:echo_uploads) and Rails.configuration.echo_uploads.folder
    Rails.configuration.echo_uploads.folder
  else
    ::File.join Rails.root, 'echo_uploads', Rails.env
  end
end