Class: Valkyrie::StorageAdapter
- Inherits:
-
Object
- Object
- Valkyrie::StorageAdapter
- Defined in:
- lib/valkyrie/storage_adapter.rb
Overview
StorageAdapter is the primary DataMapper object for binary content persistence.
Used to register and locate adapters for individual
storage backends (such as fedora, disk, etc)
Defined Under Namespace
Classes: AdapterNotFoundError, File, FileNotFound, StreamFile
Class Method Summary collapse
-
.adapter_for(id:) ⇒ Valkyrie::StorageAdapter
Return the registered storage adapter which handles the given ID.
-
.delete(id:) ⇒ Object
Search through all registered storage adapters until it finds one that can handle the passed in identifier.
-
.find(short_name) ⇒ Valkyrie::StorageAdapter
Find the adapter associated with the provided short name.
-
.find_by(id:) ⇒ Valkyrie::StorageAdapter::File
Search through all registered storage adapters until it finds one that can handle the passed in identifier.
-
.register(storage_adapter, short_name) ⇒ void
Add a storage adapter to the registry under the provided short name.
- .unregister(short_name) ⇒ void
Class Method Details
.adapter_for(id:) ⇒ Valkyrie::StorageAdapter
Return the registered storage adapter which handles the given ID.
57 58 59 60 61 62 63 64 |
# File 'lib/valkyrie/storage_adapter.rb', line 57 def adapter_for(id:) handler = storage_adapters.values.find do |storage_adapter| storage_adapter.handles?(id: id) end raise AdapterNotFoundError, 'Unable to find a StorageAdapter' if handler.nil? handler end |
.delete(id:) ⇒ Object
Search through all registered storage adapters until it finds one that can handle the passed in identifier. Then call delete on that adapter with the given identifier.
50 51 52 |
# File 'lib/valkyrie/storage_adapter.rb', line 50 def delete(id:) adapter_for(id: id).delete(id: id) end |
.find(short_name) ⇒ Valkyrie::StorageAdapter
Find the adapter associated with the provided short name
30 31 32 33 34 |
# File 'lib/valkyrie/storage_adapter.rb', line 30 def find(short_name) storage_adapters.fetch(short_name) rescue KeyError raise "Unable to find #{self} with short_name of #{short_name.inspect}. Registered adapters are #{storage_adapters.keys.inspect}" end |
.find_by(id:) ⇒ Valkyrie::StorageAdapter::File
Search through all registered storage adapters until it finds one that can handle the passed in identifier. The call find_by on that adapter with the given identifier.
42 43 44 |
# File 'lib/valkyrie/storage_adapter.rb', line 42 def find_by(id:) adapter_for(id: id).find_by(id: id) end |
.register(storage_adapter, short_name) ⇒ void
This method returns an undefined value.
Add a storage adapter to the registry under the provided short name
16 17 18 |
# File 'lib/valkyrie/storage_adapter.rb', line 16 def register(storage_adapter, short_name) storage_adapters[short_name] = storage_adapter end |
.unregister(short_name) ⇒ void
This method returns an undefined value.
22 23 24 |
# File 'lib/valkyrie/storage_adapter.rb', line 22 def unregister(short_name) storage_adapters.delete(short_name) end |