Class: Valkyrie::StorageAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/valkyrie/storage_adapter.rb

Defined Under Namespace

Classes: File, FileNotFound, StreamFile

Class Method Summary collapse

Class Method Details

.adapter_for(id:) ⇒ Object

Return the registered storage adapter which handles the given ID.


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

def adapter_for(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. The call delete on that adapter with the given identifier.

Parameters:


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

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:


25
26
27
# File 'lib/valkyrie/storage_adapter.rb', line 25

def find(short_name)
  storage_adapters[short_name]
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


35
36
37
# File 'lib/valkyrie/storage_adapter.rb', line 35

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:


12
13
14
# File 'lib/valkyrie/storage_adapter.rb', line 12

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)

18
19
20
# File 'lib/valkyrie/storage_adapter.rb', line 18

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