Class: JobIoWrapper
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- JobIoWrapper
- Defined in:
- app/models/job_io_wrapper.rb
Overview
Along with user and file_set_id, path or uploaded_file are required. If both are provided: path is used preferentially for access IF it exists; however, the uploaded_file is used preferentially for default original_name and mime_type, because it already has that information.
Primarily for jobs like IngestJob to revivify an equivalent FileActor to one that existed on the caller’s side of an asynchronous Job invocation. This involves providing slots for the metadata that might travel w/ the actor’s various supported types of @file. For example, we cannot just do:
SomeJob.perform_later(arg1, arg2, File.new('/path/to/file'))
Because we’ll get:
ActiveJob::SerializationError: Unsupported argument type: File
This also applies to Hydra::Derivatives::IoDecorator, Tempfile, etc., pretty much any IO.
Class Method Summary collapse
-
.create_with_varied_file_handling!(user:, file:, relation:, file_set:) ⇒ JobIoWrapper
Responsible for creating a JobIoWrapper from the given parameters, with a focus on sniffing out attributes from the given :file.
Instance Method Summary collapse
- #file_actor ⇒ Object
- #file_set ⇒ Object
- #ingest_file ⇒ Object
- #mime_type ⇒ Object
- #original_name ⇒ Object
Class Method Details
.create_with_varied_file_handling!(user:, file:, relation:, file_set:) ⇒ JobIoWrapper
Responsible for creating a JobIoWrapper from the given parameters, with a focus on sniffing out attributes from the given :file.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/models/job_io_wrapper.rb', line 36 def self.create_with_varied_file_handling!(user:, file:, relation:, file_set:) args = { user: user, relation: relation.to_s, file_set_id: file_set.id } if file.is_a?(Hyrax::UploadedFile) args[:uploaded_file] = file args[:path] = file.uploader.path elsif file.respond_to?(:path) args[:path] = file.path args[:original_name] = file.original_filename if file.respond_to?(:original_filename) args[:original_name] ||= file.original_name if file.respond_to?(:original_name) else raise "Require Hyrax::UploadedFile or File-like object, received #{file.class} object: #{file}" end create!(args) end |
Instance Method Details
#file_actor ⇒ Object
63 64 65 |
# File 'app/models/job_io_wrapper.rb', line 63 def file_actor Hyrax::Actors::FileActor.new(file_set, relation.to_sym, user) end |
#file_set ⇒ Object
59 60 61 |
# File 'app/models/job_io_wrapper.rb', line 59 def file_set FileSet.find(file_set_id) end |
#ingest_file ⇒ Object
67 68 69 |
# File 'app/models/job_io_wrapper.rb', line 67 def ingest_file file_actor.ingest_file(self) end |
#mime_type ⇒ Object
55 56 57 |
# File 'app/models/job_io_wrapper.rb', line 55 def mime_type super || extracted_mime_type end |
#original_name ⇒ Object
51 52 53 |
# File 'app/models/job_io_wrapper.rb', line 51 def original_name super || extracted_original_name end |