Skip to content

Commit

Permalink
Merge pull request #335 from samvera-labs/working-on-valkyrie-underst…
Browse files Browse the repository at this point in the history
…anding-part-2

Working on valkyrie understanding part 2
  • Loading branch information
Trey Pendragon committed Feb 7, 2018
2 parents ccff847 + d6da924 commit c85d4c8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/valkyrie/storage_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,15 +40,18 @@ 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:)
adapter_for(id: id).delete(id: 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
Expand Down
8 changes: 8 additions & 0 deletions spec/valkyrie/storage_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit c85d4c8

Please sign in to comment.