Class: Attach::Backends::FileSystem
Instance Method Summary
collapse
Methods inherited from Abstract
#bytesize, #digest, #initialize, #read_multi, #url
Instance Method Details
#delete(attachment) ⇒ Object
24
25
26
27
|
# File 'lib/attach/backends/file_system.rb', line 24
def delete(attachment)
path = path_for_attachment(attachment)
FileUtils.rm(path) if ::File.file?(path)
end
|
#read(attachment) ⇒ Object
8
9
10
|
# File 'lib/attach/backends/file_system.rb', line 8
def read(attachment)
::File.read(path_for_attachment(attachment))
end
|
#write(attachment, data) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/attach/backends/file_system.rb', line 12
def write(attachment, data)
path = path_for_attachment(attachment)
FileUtils.mkdir_p(::File.dirname(path))
if data.respond_to?(:path)
FileUtils.mv(data.path, path)
else
::File.open(path, 'wb') do |f|
f.write(data)
end
end
end
|