Class: EchoUploads::FilesystemStore

Inherits:
AbstractStore show all
Defined in:
lib/echo_uploads/filesystem_store.rb

Instance Method Summary collapse

Instance Method Details

#delete(key) ⇒ Object



21
22
23
24
# File 'lib/echo_uploads/filesystem_store.rb', line 21

def delete(key)
  _path = path(key)
  ::File.delete(_path) if ::File.exists?(_path)
end

#open(key) ⇒ Object



26
27
28
# File 'lib/echo_uploads/filesystem_store.rb', line 26

def open(key)
  ::File.open(path(key), 'rb', &block)
end

#path(key) ⇒ Object



30
31
32
# File 'lib/echo_uploads/filesystem_store.rb', line 30

def path(key)
  ::File.join folder, key
end

#read(key) ⇒ Object



17
18
19
# File 'lib/echo_uploads/filesystem_store.rb', line 17

def read(key)
  File.read path(key)
end

#write(key, file) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/echo_uploads/filesystem_store.rb', line 3

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