Sha256: a7edc6bb9a471ed29bdb312768092318ff24d81f2fd5de9cb3f6c737ff8bf2f9

Contents?: true

Size: 1.55 KB

Versions: 69

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

require 'logger'

module SdrClient
  module Deposit
    # Collecting all the metadata about the files for a deposit
    class UploadFilesMetadataBuilder
      # @param [Array<String>] files a list of filepaths to upload
      # @param [Hash<String,String>] mime_types a map of filenames to mime types
      # @return [Hash<String, Files::DirectUploadRequest>] the metadata for uploading the files
      def self.build(files:, mime_types:)
        new(files: files, mime_types: mime_types).build
      end

      # @param [Array<String>] files a list of filepaths to upload
      # @param [Hash<String,String>] mime_types a map of filenames to mime types
      def initialize(files:, mime_types:)
        @files = files
        @mime_types = mime_types
      end

      attr_reader :files, :mime_types

      # @return [Hash<String, Files::DirectUploadRequest>] the metadata for uploading the files
      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

      # This can be overridden in the case that the file on disk has a different
      # name than we want to repo to know about.
      def filename_for(file_path)
        ::File.basename(file_path)
      end

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

Version data entries

69 entries across 69 versions & 1 rubygems

Version Path
sdr-client-0.96.0 lib/sdr_client/deposit/upload_files_metadata_builder.rb
sdr-client-0.95.0 lib/sdr_client/deposit/upload_files_metadata_builder.rb
sdr-client-0.94.0 lib/sdr_client/deposit/upload_files_metadata_builder.rb
sdr-client-0.93.0 lib/sdr_client/deposit/upload_files_metadata_builder.rb
sdr-client-0.92.0 lib/sdr_client/deposit/upload_files_metadata_builder.rb
sdr-client-0.91.0 lib/sdr_client/deposit/upload_files_metadata_builder.rb
sdr-client-0.90.0 lib/sdr_client/deposit/upload_files_metadata_builder.rb
sdr-client-0.89.0 lib/sdr_client/deposit/upload_files_metadata_builder.rb
sdr-client-0.88.0 lib/sdr_client/deposit/upload_files_metadata_builder.rb
sdr-client-0.87.0 lib/sdr_client/deposit/upload_files_metadata_builder.rb
sdr-client-0.86.0 lib/sdr_client/deposit/upload_files_metadata_builder.rb
sdr-client-0.85.0 lib/sdr_client/deposit/upload_files_metadata_builder.rb
sdr-client-0.84.0 lib/sdr_client/deposit/upload_files_metadata_builder.rb
sdr-client-0.83.0 lib/sdr_client/deposit/upload_files_metadata_builder.rb
sdr-client-0.82.0 lib/sdr_client/deposit/upload_files_metadata_builder.rb
sdr-client-0.81.0 lib/sdr_client/deposit/upload_files_metadata_builder.rb
sdr-client-0.80.0 lib/sdr_client/deposit/upload_files_metadata_builder.rb
sdr-client-0.79.0 lib/sdr_client/deposit/upload_files_metadata_builder.rb
sdr-client-0.78.0 lib/sdr_client/deposit/upload_files_metadata_builder.rb
sdr-client-0.77.1 lib/sdr_client/deposit/upload_files_metadata_builder.rb