Class: SdrClient::Deposit::UploadFilesMetadataBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/sdr_client/deposit/upload_files_metadata_builder.rb

Overview

Collecting all the metadata about the files for a deposit

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(files:, mime_types:, basepath:) ⇒ UploadFilesMetadataBuilder

Returns a new instance of UploadFilesMetadataBuilder.

Parameters:

  • files (Array<String>)

    a list of absolute filepaths to upload

  • mime_types (Hash<String,String>)

    a map of filenames to mime types

  • basepath (String)

    path to which files are relative



20
21
22
23
24
# File 'lib/sdr_client/deposit/upload_files_metadata_builder.rb', line 20

def initialize(files:, mime_types:, basepath:)
  @files = files
  @mime_types = mime_types
  @basepath = basepath
end

Instance Attribute Details

#basepathObject (readonly)

Returns the value of attribute basepath.



26
27
28
# File 'lib/sdr_client/deposit/upload_files_metadata_builder.rb', line 26

def basepath
  @basepath
end

#filesObject (readonly)

Returns the value of attribute files.



26
27
28
# File 'lib/sdr_client/deposit/upload_files_metadata_builder.rb', line 26

def files
  @files
end

#mime_typesObject (readonly)

Returns the value of attribute mime_types.



26
27
28
# File 'lib/sdr_client/deposit/upload_files_metadata_builder.rb', line 26

def mime_types
  @mime_types
end

Class Method Details

.build(files:, mime_types:, basepath:) ⇒ Hash<String, Files::DirectUploadRequest>

Returns the metadata for uploading the files.

Parameters:

  • files (Array<String>)

    a list of relative filepaths to upload

  • mime_types (Hash<String,String>)

    a map of filenames to mime types

  • basepath (String)

    path to which files are relative

Returns:



13
14
15
# File 'lib/sdr_client/deposit/upload_files_metadata_builder.rb', line 13

def self.build(files:, mime_types:, basepath:)
  new(files: files, mime_types: mime_types, basepath: basepath).build
end

Instance Method Details

#absolute_filepath_for(filepath) ⇒ Object



37
38
39
# File 'lib/sdr_client/deposit/upload_files_metadata_builder.rb', line 37

def absolute_filepath_for(filepath)
  ::File.join(basepath, filepath)
end

#buildHash<String, Files::DirectUploadRequest>

Returns the metadata for uploading the files.

Returns:



29
30
31
32
33
34
35
# File 'lib/sdr_client/deposit/upload_files_metadata_builder.rb', line 29

def build
  files.each_with_object({}) do |filepath, obj|
    obj[filepath] = Files::DirectUploadRequest.from_file(absolute_filepath_for(filepath),
                                                         file_name: filepath,
                                                         content_type: mime_types[filepath])
  end
end