diff --git a/lib/valkyrie/storage_adapter.rb b/lib/valkyrie/storage_adapter.rb index c2c4b0714..2350e0bdc 100644 --- a/lib/valkyrie/storage_adapter.rb +++ b/lib/valkyrie/storage_adapter.rb @@ -22,8 +22,11 @@ def unregister(short_name) # Find the adapter associated with the provided short name # @param short_name [Symbol] # @return [Valkyrie::StorageAdapter] + # @raise Valkyrie::StorageAdapter::AdapterNotFoundError when we are unable to find the named adapter def find(short_name) - storage_adapters[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 # Search through all registered storage adapters until it finds one that @@ -37,7 +40,7 @@ def find_by(id:) end # Search through all registered storage adapters until it finds one that - # can handle the passed in identifier. The call delete on that adapter + # can handle the passed in identifier. Then call delete on that adapter # with the given identifier. # @param id [Valkyrie::ID] def delete(id:) @@ -45,7 +48,10 @@ def delete(id:) end # Return the registered storage adapter which handles the given ID. + # @param id [Valkyrie::ID] + # @return [Valkyrie::StorageAdapter] 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 diff --git a/spec/valkyrie/storage_adapter_spec.rb b/spec/valkyrie/storage_adapter_spec.rb index fa22002e8..08f9ffedd 100644 --- a/spec/valkyrie/storage_adapter_spec.rb +++ b/spec/valkyrie/storage_adapter_spec.rb @@ -15,6 +15,14 @@ end end + describe '.find' do + context "with an unregistered adapter" do + it "raises a #{described_class}::AdapterNotFoundError" do + expect { described_class.find(:obviously_missing) }.to raise_error(RuntimeError, /:obviously_missing/) + end + end + end + describe ".find_by" do it "delegates down to its storage_adapters to find one which handles the given identifier" do file = instance_double(Valkyrie::StorageAdapter::StreamFile, id: "yo")