class Attach::Backends::Abstract

Public Class Methods

new(config = {}) click to toggle source
# File lib/attach/backends/abstract.rb, line 5
def initialize(config = {})
  @config = config
end

Public Instance Methods

bytesize(binary) click to toggle source

Return the bytesize of a given binary

# File lib/attach/backends/abstract.rb, line 64
def bytesize(binary)
  if binary.respond_to?(:path)
    ::File.size(binary.path)
  else
    binary.bytesize
  end
end
delete(attachment) click to toggle source

 Delete the data for the given attachment

# File lib/attach/backends/abstract.rb, line 24
def delete(attachment)
end
digest(binary) click to toggle source

Return the SHA1 digest of a given binary

# File lib/attach/backends/abstract.rb, line 47
def digest(binary)
  if binary.respond_to?(:path)
    sha1 = Digest::SHA1.new
    binary.binmode
    binary.rewind
    while chunk = binary.read(1024 * 1024)
      sha1.update(chunk)
    end
    sha1.hexdigest
  else
    Digest::SHA1.hexdigest(binary)
  end
end
read(attachment) click to toggle source

 Return the data for the given attachment

# File lib/attach/backends/abstract.rb, line 12
def read(attachment)
end
read_multi(attachments) click to toggle source

 Return binaries for a set of files. They should be returned as a hash consisting

of the attachment ID followed by the data
# File lib/attach/backends/abstract.rb, line 38
def read_multi(attachments)
  attachments.compact.each_with_object({}) do |attachment, hash|
    hash[attachment] = read(attachment)
  end
end
url(attachment) click to toggle source

Return the URL that this attachment can be accessed at

# File lib/attach/backends/abstract.rb, line 30
def url(attachment)
  "#{Attach.asset_host}/attachment/#{attachment.token}/#{attachment.file_name}"
end
write(attachment, data) click to toggle source

 Write data for the given attachment

# File lib/attach/backends/abstract.rb, line 18
def write(attachment, data)
end