Class: Valkyrie::Storage::Fedora
- Inherits:
-
Object
- Object
- Valkyrie::Storage::Fedora
- Defined in:
- lib/valkyrie/storage/fedora.rb
Overview
Implements the DataMapper Pattern to store binary data in fedora
Constant Summary collapse
- PROTOCOL =
'fedora://'
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
-
#delete(id:) ⇒ Object
Delete the file in Fedora associated with the given identifier.
-
#find_by(id:) ⇒ Valkyrie::StorageAdapter::StreamFile
Return the file associated with the given identifier.
-
#handles?(id:) ⇒ Boolean
True if this adapter can handle this type of identifer.
-
#initialize(connection:) ⇒ Fedora
constructor
A new instance of Fedora.
- #upload(file:, original_filename:, resource:) ⇒ Valkyrie::StorageAdapter::StreamFile
Constructor Details
#initialize(connection:) ⇒ Fedora
Returns a new instance of Fedora.
7 8 9 |
# File 'lib/valkyrie/storage/fedora.rb', line 7 def initialize(connection:) @connection = connection end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
5 6 7 |
# File 'lib/valkyrie/storage/fedora.rb', line 5 def connection @connection end |
Instance Method Details
#delete(id:) ⇒ Object
Delete the file in Fedora associated with the given identifier.
46 47 48 |
# File 'lib/valkyrie/storage/fedora.rb', line 46 def delete(id:) ActiveFedora::File.new(active_fedora_identifier(id: id)).ldp_source.delete end |
#find_by(id:) ⇒ Valkyrie::StorageAdapter::StreamFile
Return the file associated with the given identifier
21 22 23 24 25 |
# File 'lib/valkyrie/storage/fedora.rb', line 21 def find_by(id:) Valkyrie::StorageAdapter::StreamFile.new(id: id, io: response(id: id)) rescue ::Ldp::Gone raise Valkyrie::StorageAdapter::FileNotFound end |
#handles?(id:) ⇒ Boolean
Returns true if this adapter can handle this type of identifer.
13 14 15 |
# File 'lib/valkyrie/storage/fedora.rb', line 13 def handles?(id:) id.to_s.start_with?(PROTOCOL) end |
#upload(file:, original_filename:, resource:) ⇒ Valkyrie::StorageAdapter::StreamFile
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/valkyrie/storage/fedora.rb', line 31 def upload(file:, original_filename:, resource:) # TODO: this is a very naive aproach. Change to PCDM identifier = resource.id.to_uri + '/original' ActiveFedora::File.new(identifier) do |af| af.content = file af.original_name = original_filename af.save! af..set_value(:type, af..type + [::RDF::URI('http://pcdm.org/use#OriginalFile')]) af..save end find_by(id: Valkyrie::ID.new(identifier.to_s.sub(/^.+\/\//, PROTOCOL))) end |