Class: Valkyrie::Storage::Memory

Inherits:
Object
  • Object
show all
Defined in:
lib/valkyrie/storage/memory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMemory

Returns a new instance of Memory.


5
6
7
# File 'lib/valkyrie/storage/memory.rb', line 5

def initialize
  @cache = {}
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache


4
5
6
# File 'lib/valkyrie/storage/memory.rb', line 4

def cache
  @cache
end

Instance Method Details

#delete(id:) ⇒ Object

Delete the file on disk associated with the given identifier.

Parameters:


35
36
37
38
# File 'lib/valkyrie/storage/memory.rb', line 35

def delete(id:)
  cache.delete(id)
  nil
end

#find_by(id:) ⇒ Valkyrie::StorageAdapter::StreamFile

Return the file associated with the given identifier

Parameters:

Returns:

Raises:

  • Valkyrie::StorageAdapter::FileNotFound if nothing is found


22
23
24
25
# File 'lib/valkyrie/storage/memory.rb', line 22

def find_by(id:)
  raise Valkyrie::StorageAdapter::FileNotFound unless cache[id]
  cache[id]
end

#handles?(id:) ⇒ Boolean

Returns true if this adapter can handle this type of identifer.

Parameters:

Returns:

  • (Boolean)

    true if this adapter can handle this type of identifer


29
30
31
# File 'lib/valkyrie/storage/memory.rb', line 29

def handles?(id:)
  id.to_s.start_with?("memory://")
end

#upload(file:, original_filename:, resource: nil) ⇒ Valkyrie::StorageAdapter::StreamFile

Parameters:

Returns:


13
14
15
16
# File 'lib/valkyrie/storage/memory.rb', line 13

def upload(file:, original_filename:, resource: nil)
  identifier = Valkyrie::ID.new("memory://#{resource.id}")
  cache[identifier] = Valkyrie::StorageAdapter::StreamFile.new(id: identifier, io: file)
end