class Attach::Backends::FileSystem

Public Instance Methods

delete(attachment) click to toggle source
# 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) click to toggle source
# File lib/attach/backends/file_system.rb, line 8
def read(attachment)
  ::File.read(path_for_attachment(attachment))
end
write(attachment, data) click to toggle source
# 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

Private Instance Methods

path_for_attachment(attachment) click to toggle source
# File lib/attach/backends/file_system.rb, line 35
def path_for_attachment(attachment)
  ::File.join(root_dir, attachment.token[0,2], attachment.token[2,2], attachment.token[4,40])
end
root_dir() click to toggle source
# File lib/attach/backends/file_system.rb, line 31
def root_dir
  @config[:root] ||= Rails.root.join('attachments')
end