class Refile::Fog::Backend

Attributes

directory[R]
max_size[R]

Public Class Methods

new(directory:, max_size: nil, prefix: nil, hasher: Refile::RandomHasher.new, connection: nil, **options) click to toggle source
# File lib/refile/fog.rb, line 12
def initialize(directory:, max_size: nil, prefix: nil, hasher: Refile::RandomHasher.new, connection: nil, **options)
  @connection = connection || ::Fog::Storage.new(options)
  @prefix = prefix
  @hasher = hasher
  @max_size = max_size

  @directory = @connection.directories.new(key: directory)
end

Public Instance Methods

clear!(confirm = nil) click to toggle source
# File lib/refile/fog.rb, line 60
def clear!(confirm = nil)
  raise Refile::Confirm unless confirm == :confirm
  @directory.files.select { |f| f.key.start_with?(@prefix.to_s) }.each(&:destroy)
end
delete(id) click to toggle source
# File lib/refile/fog.rb, line 33
          def delete(id)
  file = head(id)
  file.destroy if file
end
exists?(id) click to toggle source
# File lib/refile/fog.rb, line 52
          def exists?(id)
  !!head(id)
end
get(id) click to toggle source
# File lib/refile/fog.rb, line 29
          def get(id)
  Refile::File.new(self, id)
end
head(id) click to toggle source
# File lib/refile/fog.rb, line 56
          def head(id)
  @directory.files.head(path(id))
end
open(id) click to toggle source
# File lib/refile/fog.rb, line 38
          def open(id)
  StringIO.new(read(id))
end
read(id) click to toggle source
# File lib/refile/fog.rb, line 42
          def read(id)
  file = @directory.files.get(path(id))
  file.body if file
end
size(id) click to toggle source
# File lib/refile/fog.rb, line 47
          def size(id)
  file = head(id)
  file.content_length if file
end
upload(uploadable) click to toggle source
# File lib/refile/fog.rb, line 21
                  def upload(uploadable)
  id = @hasher.hash(uploadable)

  @directory.files.create(key: path(id), body: uploadable.read)

  Refile::File.new(self, id)
end

Private Instance Methods

path(id) click to toggle source
# File lib/refile/fog.rb, line 67
          def path(id)
  ::File.join(*@prefix, id)
end