Class: Attach::Backends::FileSystem
Instance Method Summary
collapse
Methods inherited from Abstract
#bytesize, #digest, #initialize, #read_multi, #url
Instance Method Details
#delete(attachment) ⇒ Object
29
30
31
32
33
|
# File 'lib/attach/backends/file_system.rb', line 29
def delete(attachment)
path = path_for_attachment(attachment)
FileUtils.rm(path) if ::File.file?(path)
path
end
|
#read(attachment) ⇒ Object
10
11
12
13
|
# File 'lib/attach/backends/file_system.rb', line 10
def read(attachment)
file = File.new(path_for_attachment(attachment))
BlobTypes::File.new(file)
end
|
#write(attachment, blob) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/attach/backends/file_system.rb', line 15
def write(attachment, blob)
path = path_for_attachment(attachment)
FileUtils.mkdir_p(::File.dirname(path))
if blob.is_a?(BlobTypes::File)
FileUtils.mv(blob.file.path, path)
return path
end
::File.binwrite(path, blob.read)
path
end
|