Class: Valkyrie::StorageAdapter

Inherits:
Object
  • Object
show all
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

Class Method Details

.adapter_for(id:) ⇒ Valkyrie::StorageAdapter

Return the registered storage adapter which handles the given ID.

Parameters:

Returns:

Raises:


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.

Parameters:


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

Parameters:

  • short_name (Symbol)

Returns:

Raises:

  • Valkyrie::StorageAdapter::AdapterNotFoundError when we are unable to find the named adapter


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.

Parameters:

Returns:

Raises:

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


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

Parameters:


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.

Parameters:

  • short_name (Symbol)

22
23
24
# File 'lib/valkyrie/storage_adapter.rb', line 22

def unregister(short_name)
  storage_adapters.delete(short_name)
end