class Refile::Memory::Backend

Attributes

directory[R]
max_size[R]

Public Class Methods

new(max_size: nil, hasher: Refile::RandomHasher.new) click to toggle source
# File lib/refile/memory.rb, line 12
def initialize(max_size: nil, hasher: Refile::RandomHasher.new)
  @hasher = hasher
  @max_size = max_size
  @store = {}
end

Public Instance Methods

clear!(confirm = nil) click to toggle source
# File lib/refile/memory.rb, line 50
def clear!(confirm = nil)
  raise Refile::Confirm unless confirm == :confirm
  @store = {}
end
delete(id) click to toggle source
# File lib/refile/memory.rb, line 30
          def delete(id)
  @store.delete(id)
end
exists?(id) click to toggle source
# File lib/refile/memory.rb, line 46
          def exists?(id)
  @store.has_key?(id)
end
get(id) click to toggle source
# File lib/refile/memory.rb, line 26
          def get(id)
  Refile::File.new(self, id)
end
open(id) click to toggle source
# File lib/refile/memory.rb, line 34
          def open(id)
  StringIO.new(@store[id])
end
read(id) click to toggle source
# File lib/refile/memory.rb, line 38
          def read(id)
  @store[id]
end
size(id) click to toggle source
# File lib/refile/memory.rb, line 42
          def size(id)
  @store[id].bytesize if exists?(id)
end
upload(uploadable) click to toggle source
# File lib/refile/memory.rb, line 18
                  def upload(uploadable)
  id = @hasher.hash(uploadable)

  @store[id] = uploadable.read

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