Class: SdrClient::Deposit::UploadFilesMetadataBuilder
- Inherits:
-
Object
- Object
- SdrClient::Deposit::UploadFilesMetadataBuilder
- 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
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#mime_types ⇒ Object
readonly
Returns the value of attribute mime_types.
Class Method Summary collapse
-
.build(files:, mime_types:) ⇒ Hash<String, Files::DirectUploadRequest>
The metadata for uploading the files.
Instance Method Summary collapse
-
#build ⇒ Hash<String, Files::DirectUploadRequest>
The metadata for uploading the files.
-
#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.
-
#initialize(files:, mime_types:) ⇒ UploadFilesMetadataBuilder
constructor
A new instance of UploadFilesMetadataBuilder.
- #mime_type_for(file_path) ⇒ Object
Constructor Details
#initialize(files:, mime_types:) ⇒ UploadFilesMetadataBuilder
Returns a new instance of UploadFilesMetadataBuilder.
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
#files ⇒ Object (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_types ⇒ Object (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.
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
#build ⇒ Hash<String, Files::DirectUploadRequest>
Returns the metadata for uploading the files.
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 |