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:) ⇒ Object

Return the registered storage adapter which handles the given ID.

Parameters:

Returns:

  • (Object)

    the storage adapter

Raises:



59
60
61
62
63
64
65
66
# File 'lib/valkyrie/storage_adapter.rb', line 59

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:



51
52
53
# File 'lib/valkyrie/storage_adapter.rb', line 51

def delete(id:)
  adapter_for(id: id).delete(id: id)
end

.find(short_name) ⇒ Object

Find the adapter associated with the provided short name

Parameters:

  • short_name (Symbol)

Returns:

  • (Object)

    the storage adapter

Raises:

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



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

def find(short_name)
  storage_adapters.fetch(short_name)
rescue KeyError
  raise AdapterNotFoundError, "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



43
44
45
# File 'lib/valkyrie/storage_adapter.rb', line 43

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