Class: SdrClient::RedesignedClient::UploadFilesMetadataBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/sdr_client/redesigned_client/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



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

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.



24
25
26
# File 'lib/sdr_client/redesigned_client/upload_files_metadata_builder.rb', line 24

def basepath
  @basepath
end

#filesObject (readonly)

Returns the value of attribute files.



24
25
26
# File 'lib/sdr_client/redesigned_client/upload_files_metadata_builder.rb', line 24

def files
  @files
end

#mime_typesObject (readonly)

Returns the value of attribute mime_types.



24
25
26
# File 'lib/sdr_client/redesigned_client/upload_files_metadata_builder.rb', line 24

def mime_types
  @mime_types
end

Class Method Details

.build(files:, mime_types:, basepath:) ⇒ Hash<String, 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:



11
12
13
# File 'lib/sdr_client/redesigned_client/upload_files_metadata_builder.rb', line 11

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



35
36
37
# File 'lib/sdr_client/redesigned_client/upload_files_metadata_builder.rb', line 35

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

#buildHash<String, DirectUploadRequest>

Returns the metadata for uploading the files.

Returns:



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

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