Skip to content

Commit

Permalink
Addresses documentation issue in samvera#951
Browse files Browse the repository at this point in the history
Also:
- Corrects the documentation of Valkyrie::StorageAdapter::File#valid?
- Implements AdapterNotFoundError as documented on Valkyrie::StorageAdapter.find
  and in test description. (I'm not sure if this would technically be a breaking
  change since the raised exception would not be a RuntimeError.)
  • Loading branch information
dchandekstark committed Apr 24, 2024
1 parent ccb2677 commit 014186d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions lib/valkyrie/storage_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ def unregister(short_name)

# Find the adapter associated with the provided short name
# @param short_name [Symbol]
# @return [Valkyrie::StorageAdapter]
# @return [Object] the storage adapter
# @raise Valkyrie::StorageAdapter::AdapterNotFoundError when we are unable to find the named adapter
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}"
raise AdapterNotFoundError, "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 @@ -53,7 +54,8 @@ def delete(id:)

# Return the registered storage adapter which handles the given ID.
# @param id [Valkyrie::ID]
# @return [Valkyrie::StorageAdapter]
# @return [Object] the storage adapter
# @raise [Valkyrie::StorageAdapter::AdapterNotFoundError]
def adapter_for(id:)
handler = storage_adapters.values.find do |storage_adapter|
storage_adapter.handles?(id: id)
Expand Down Expand Up @@ -89,7 +91,7 @@ def checksum(digests:)
end

# @param size [Integer]
# @param digests [Array<Digest>]
# @param digests [Array<Hash>] array of hashes, each of which maps a digest algorithm name to a digest value.
# @return [Boolean]
def valid?(size: nil, digests:)
return false if size && io.size.to_i != size.to_i
Expand Down
2 changes: 1 addition & 1 deletion spec/valkyrie/storage_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
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/)
expect { described_class.find(:obviously_missing) }.to raise_error(Valkyrie::StorageAdapter::AdapterNotFoundError, /:obviously_missing/)
end
end
end
Expand Down

0 comments on commit 014186d

Please sign in to comment.