app/models/job_io_wrapper.rb in hyrax-3.0.0.pre.beta2 vs app/models/job_io_wrapper.rb in hyrax-3.0.0.pre.beta3

- old
+ new

@@ -20,11 +20,11 @@ belongs_to :uploaded_file, optional: true, class_name: 'Hyrax::UploadedFile' validates :uploaded_file, presence: true, if: proc { |x| x.path.blank? } validates :file_set_id, presence: true after_initialize :static_defaults - delegate :read, :size, to: :file + delegate :read, to: :file # Responsible for creating a JobIoWrapper from the given parameters, with a # focus on sniffing out attributes from the given :file. # # @param [User] user - The user requesting to create this instance @@ -54,37 +54,52 @@ def mime_type super || extracted_mime_type end - def file_set - FileSet.find(file_set_id) + def size + return file.size.to_s if file.respond_to? :size + return file.stat.size.to_s if file.respond_to? :stat + nil # unable to determine end + def file_set(use_valkyrie: false) + return FileSet.find(file_set_id) unless use_valkyrie + Hyrax.query_service.find_by(id: Valkyrie::ID.new(file_set_id)) + end + def file_actor Hyrax::Actors::FileActor.new(file_set, relation.to_sym, user) end + # @return [Hyrax::FileMetadata, FalseClass] the created file metadata on success, false on failure def ingest_file file_actor.ingest_file(self) end + def to_file_metadata + Hyrax::FileMetadata.new(label: original_name, + original_filename: original_name, + mime_type: mime_type, + use: [Valkyrie::Vocab::PCDMUse.OriginalFile]) + end + + # The magic that switches *once* between local filepath and CarrierWave file + # @return [File, StringIO, #read] File-like object ready to #read + def file + @file ||= (file_from_path || file_from_uploaded_file!) + end + private def extracted_original_name eon = uploaded_file.uploader.filename if uploaded_file eon ||= File.basename(path) if path.present? # note: uploader.filename is `nil` with uncached remote files (e.g. AWSFile) eon end def extracted_mime_type uploaded_file ? uploaded_file.uploader.content_type : Hydra::PCDM::GetMimeTypeForFile.call(original_name) - end - - # The magic that switches *once* between local filepath and CarrierWave file - # @return [File, StringIO, #read] File-like object ready to #read - def file - @file ||= (file_from_path || file_from_uploaded_file!) end # @return [File, StringIO] depending on CarrierWave configuration # @raise when uploaded_file *becomes* required but is missing def file_from_uploaded_file!