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: 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:



56
57
58
59
60
61
# File 'lib/valkyrie/storage_adapter.rb', line 56

def adapter_for(id:)
  # TODO: Determine the appropriate response when we have an unhandled :id
  storage_adapters.values.find do |storage_adapter|
    storage_adapter.handles?(id: id)
  end
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:



49
50
51
# File 'lib/valkyrie/storage_adapter.rb', line 49

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



29
30
31
32
33
# File 'lib/valkyrie/storage_adapter.rb', line 29

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



41
42
43
# File 'lib/valkyrie/storage_adapter.rb', line 41

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:



15
16
17
# File 'lib/valkyrie/storage_adapter.rb', line 15

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)


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

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