Class: Hyrax::FileSetDerivativesService
- Inherits:
-
Object
- Object
- Hyrax::FileSetDerivativesService
- Defined in:
- app/services/hyrax/file_set_derivatives_service.rb
Overview
Responsible for creating and cleaning up the derivatives of a file_set
Instance Attribute Summary collapse
-
#file_set ⇒ Object
readonly
Returns the value of attribute file_set.
Instance Method Summary collapse
- #cleanup_derivatives ⇒ Object
- #create_derivatives(filename) ⇒ Object
-
#derivative_url(destination_name) ⇒ Object
The destination_name parameter has to match up with the file parameter passed to the DownloadsController.
-
#initialize(file_set) ⇒ FileSetDerivativesService
constructor
A new instance of FileSetDerivativesService.
- #uri ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(file_set) ⇒ FileSetDerivativesService
Returns a new instance of FileSetDerivativesService.
9 10 11 |
# File 'app/services/hyrax/file_set_derivatives_service.rb', line 9 def initialize(file_set) @file_set = file_set end |
Instance Attribute Details
#file_set ⇒ Object (readonly)
Returns the value of attribute file_set.
5 6 7 |
# File 'app/services/hyrax/file_set_derivatives_service.rb', line 5 def file_set @file_set end |
Instance Method Details
#cleanup_derivatives ⇒ Object
22 23 24 25 26 |
# File 'app/services/hyrax/file_set_derivatives_service.rb', line 22 def cleanup_derivatives derivative_path_factory.derivatives_for_reference(file_set).each do |path| FileUtils.rm_f(path) end end |
#create_derivatives(filename) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'app/services/hyrax/file_set_derivatives_service.rb', line 32 def create_derivatives(filename) case mime_type when *Hyrax.config.derivative_mime_type_mappings[:pdf] then create_pdf_derivatives(filename) when *Hyrax.config.derivative_mime_type_mappings[:office] then create_office_document_derivatives(filename) when *Hyrax.config.derivative_mime_type_mappings[:audio] then create_audio_derivatives(filename) when *Hyrax.config.derivative_mime_type_mappings[:video] then create_video_derivatives(filename) when *Hyrax.config.derivative_mime_type_mappings[:image] then create_image_derivatives(filename) end end |
#derivative_url(destination_name) ⇒ Object
The destination_name parameter has to match up with the file parameter passed to the DownloadsController
44 45 46 47 |
# File 'app/services/hyrax/file_set_derivatives_service.rb', line 44 def derivative_url(destination_name) path = derivative_path_factory.derivative_path_for_reference(derivative_url_target, destination_name) URI("file://#{path}").to_s end |
#uri ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'app/services/hyrax/file_set_derivatives_service.rb', line 13 def uri # If given a FileMetadata object, use its parent ID. if file_set.respond_to?(:file_set_id) file_set.file_set_id.to_s else file_set.uri end end |
#valid? ⇒ Boolean
28 29 30 |
# File 'app/services/hyrax/file_set_derivatives_service.rb', line 28 def valid? supported_mime_types.include?(mime_type) end |