Class: Valkyrie::Storage::Memory
- Inherits:
-
Object
- Object
- Valkyrie::Storage::Memory
- Defined in:
- lib/valkyrie/storage/memory.rb
Overview
Note:
this adapter is used primarily for testing, and is not recommended in cases where you want to preserve real data
Implements the DataMapper Pattern to store binary data in memory
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
Instance Method Summary collapse
-
#delete(id:) ⇒ Object
Delete the file on disk associated with the given identifier.
-
#find_by(id:) ⇒ Valkyrie::StorageAdapter::StreamFile
Return the file associated with the given identifier.
-
#handles?(id:) ⇒ Boolean
True if this adapter can handle this type of identifer.
-
#initialize ⇒ Memory
constructor
A new instance of Memory.
- #upload(file:, original_filename:, resource: nil) ⇒ Valkyrie::StorageAdapter::StreamFile
Constructor Details
#initialize ⇒ Memory
Returns a new instance of Memory.
9 10 11 |
# File 'lib/valkyrie/storage/memory.rb', line 9 def initialize @cache = {} end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
8 9 10 |
# File 'lib/valkyrie/storage/memory.rb', line 8 def cache @cache end |
Instance Method Details
#delete(id:) ⇒ Object
Delete the file on disk associated with the given identifier.
39 40 41 42 |
# File 'lib/valkyrie/storage/memory.rb', line 39 def delete(id:) cache.delete(id) nil end |
#find_by(id:) ⇒ Valkyrie::StorageAdapter::StreamFile
Return the file associated with the given identifier
26 27 28 29 |
# File 'lib/valkyrie/storage/memory.rb', line 26 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.
33 34 35 |
# File 'lib/valkyrie/storage/memory.rb', line 33 def handles?(id:) id.to_s.start_with?("memory://") end |
#upload(file:, original_filename:, resource: nil) ⇒ Valkyrie::StorageAdapter::StreamFile
17 18 19 20 |
# File 'lib/valkyrie/storage/memory.rb', line 17 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 |