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, **_extra_arguments) ⇒ 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.
40 41 42 43 |
# File 'lib/valkyrie/storage/memory.rb', line 40 def delete(id:) cache.delete(id) nil end |
#find_by(id:) ⇒ Valkyrie::StorageAdapter::StreamFile
Return the file associated with the given identifier
27 28 29 30 |
# File 'lib/valkyrie/storage/memory.rb', line 27 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.
34 35 36 |
# File 'lib/valkyrie/storage/memory.rb', line 34 def handles?(id:) id.to_s.start_with?("memory://") end |
#upload(file:, original_filename:, resource: nil, **_extra_arguments) ⇒ Valkyrie::StorageAdapter::StreamFile
18 19 20 21 |
# File 'lib/valkyrie/storage/memory.rb', line 18 def upload(file:, original_filename:, resource: nil, **_extra_arguments) identifier = Valkyrie::ID.new("memory://#{resource.id}") cache[identifier] = Valkyrie::StorageAdapter::StreamFile.new(id: identifier, io: file) end |