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:) ⇒ UploadFilesMetadataBuilder

Returns a new instance of UploadFilesMetadataBuilder.

Parameters:

  • files (Array<String>)

    a list of filepaths to upload

  • mime_types (Hash<String,String>)

    a map of filenames to mime types



18
19
20
21
# File 'lib/sdr_client/deposit/upload_files_metadata_builder.rb', line 18

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

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



23
24
25
# File 'lib/sdr_client/deposit/upload_files_metadata_builder.rb', line 23

def files
  @files
end

#mime_typesObject (readonly)

Returns the value of attribute mime_types.



23
24
25
# File 'lib/sdr_client/deposit/upload_files_metadata_builder.rb', line 23

def mime_types
  @mime_types
end

Class Method Details

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

Returns the metadata for uploading the files.

Parameters:

  • files (Array<String>)

    a list of filepaths to upload

  • mime_types (Hash<String,String>)

    a map of filenames to mime types

Returns:



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

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

Instance Method Details

#buildHash<String, Files::DirectUploadRequest>

Returns the metadata for uploading the files.

Returns:



26
27
28
29
30
31
32
# File 'lib/sdr_client/deposit/upload_files_metadata_builder.rb', line 26

def build
  files.each_with_object({}) do |path, obj|
    obj[path] = Files::DirectUploadRequest.from_file(path,
                                                     file_name: filename_for(path),
                                                     content_type: mime_type_for(path))
  end
end

#filename_for(file_path) ⇒ Object

This can be overridden in the case that the file on disk has a different name than we want to repo to know about.



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

def filename_for(file_path)
  ::File.basename(file_path)
end

#mime_type_for(file_path) ⇒ Object



40
41
42
# File 'lib/sdr_client/deposit/upload_files_metadata_builder.rb', line 40

def mime_type_for(file_path)
  mime_types[filename_for(file_path)]
end