Class: Wings::Valkyrie::Storage

Inherits:
Valkyrie::Storage::Fedora
  • Object
show all
Defined in:
lib/wings/valkyrie/storage.rb

Overview

This is a Wings storage adapter designed for compatibility with Hydra::Pcdm/Hydra::Works.

Where the built-in ‘Valkyrie::Storage::Fedora` adapter uploads files without LDP containment relationships (via HTTP PUT), this adapter supports adding files to a `/files` container when a `FileSet` is passed as the `resource:` argument.

If a non ‘#file_set?` resource is passed, the logic is very similar to the built-in storage adapter.

For use with Hyrax, this adapter defaults to Fedora 4.

Constant Summary collapse

DEFAULT_CTYPE =
'application/octet-stream'
FILES_PATH =
'files'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection: Ldp::Client.new(ActiveFedora.fedora.host), base_path: ActiveFedora.fedora.base_path, fedora_version: 4) ⇒ Storage

Returns a new instance of Storage.



24
25
26
# File 'lib/wings/valkyrie/storage.rb', line 24

def initialize(connection: Ldp::Client.new(ActiveFedora.fedora.host), base_path: ActiveFedora.fedora.base_path, fedora_version: 4)
  super
end

Class Method Details

.cast_to_valkyrie_id(id) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



30
31
32
# File 'lib/wings/valkyrie/storage.rb', line 30

def self.cast_to_valkyrie_id(id)
  ::Valkyrie::ID.new(id.to_s.sub(/^.+\/\//, PROTOCOL))
end

Instance Method Details

#upload(file:, original_filename:, resource:, content_type: DEFAULT_CTYPE, resource_uri_transformer: default_resource_uri_transformer, use: Hydra::PCDM::Vocab::PCDMTerms.File, id_hint: 'original', **_extra_arguments) ⇒ Object

rubocop:disable Metrics/ParameterLists



34
35
36
37
38
39
40
41
42
43
# File 'lib/wings/valkyrie/storage.rb', line 34

def upload(file:, original_filename:, resource:, content_type: DEFAULT_CTYPE, # rubocop:disable Metrics/ParameterLists
           resource_uri_transformer: default_resource_uri_transformer, use: Hydra::PCDM::Vocab::PCDMTerms.File, # rubocop:disable Lint/UnusedMethodArgument
           id_hint: 'original', **_extra_arguments)
  id = if resource.try(:file_set?)
         upload_with_works(resource: resource, file: file, use: use)
       else
         return super(file: file, original_filename: original_filename, resource: resource, content_type: content_type, resource_uri_transformer: resource_uri_transformer_factory(id_hint))
       end
  find_by(id: cast_to_valkyrie_id(id))
end