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
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#fedora_version ⇒ Object
readonly
Returns the value of attribute fedora_version.
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:, base_path: "/", fedora_version: 4) ⇒ Fedora
constructor
A new instance of Fedora.
- #upload(file:, original_filename:, resource:) ⇒ Valkyrie::StorageAdapter::StreamFile
Constructor Details
#initialize(connection:, base_path: "/", fedora_version: 4) ⇒ Fedora
Returns a new instance of Fedora.
9 10 11 12 13 14 15 |
# File 'lib/valkyrie/storage/fedora.rb', line 9 def initialize(connection:, base_path: "/", fedora_version: 4) @connection = connection @base_path = base_path @fedora_version = fedora_version warn "[DEPRECATION] `fedora_version` will default to 5 in the next major release." unless fedora_version end |
Instance Attribute Details
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
5 6 7 |
# File 'lib/valkyrie/storage/fedora.rb', line 5 def base_path @base_path end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
5 6 7 |
# File 'lib/valkyrie/storage/fedora.rb', line 5 def connection @connection end |
#fedora_version ⇒ Object (readonly)
Returns the value of attribute fedora_version.
5 6 7 |
# File 'lib/valkyrie/storage/fedora.rb', line 5 def fedora_version @fedora_version end |
Instance Method Details
#delete(id:) ⇒ Object
Delete the file in Fedora associated with the given identifier.
52 53 54 |
# File 'lib/valkyrie/storage/fedora.rb', line 52 def delete(id:) connection.http.delete(fedora_identifier(id: id)) end |
#find_by(id:) ⇒ Valkyrie::StorageAdapter::StreamFile
Return the file associated with the given identifier
27 28 29 |
# File 'lib/valkyrie/storage/fedora.rb', line 27 def find_by(id:) Valkyrie::StorageAdapter::StreamFile.new(id: id, io: response(id: id)) end |
#handles?(id:) ⇒ Boolean
Returns true if this adapter can handle this type of identifer.
19 20 21 |
# File 'lib/valkyrie/storage/fedora.rb', line 19 def handles?(id:) id.to_s.start_with?(PROTOCOL) end |
#upload(file:, original_filename:, resource:) ⇒ Valkyrie::StorageAdapter::StreamFile
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/valkyrie/storage/fedora.rb', line 35 def upload(file:, original_filename:, resource:) identifier = id_to_uri(resource.id) + '/original' sha1 = fedora_version == 5 ? "sha" : "sha1" connection.http.put do |request| request.url identifier request.headers['Content-Type'] = file.content_type request.headers['Content-Disposition'] = "attachment; filename=\"#{original_filename}\"" request.headers['digest'] = "#{sha1}=#{Digest::SHA1.file(file)}" request.headers['link'] = "<http://www.w3.org/ns/ldp#NonRDFSource>; rel=\"type\"" io = Faraday::UploadIO.new(file.tempfile.path, file.content_type) request.body = io end find_by(id: Valkyrie::ID.new(identifier.to_s.sub(/^.+\/\//, PROTOCOL))) end |