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.
- #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
13 14 15 16 17 |
# File 'app/services/hyrax/file_set_derivatives_service.rb', line 13 def cleanup_derivatives derivative_path_factory.derivatives_for_reference(file_set).each do |path| FileUtils.rm_f(path) end end |
#create_derivatives(filename) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'app/services/hyrax/file_set_derivatives_service.rb', line 23 def create_derivatives(filename) case mime_type when *file_set.class.pdf_mime_types then create_pdf_derivatives(filename) when *file_set.class.office_document_mime_types then create_office_document_derivatives(filename) when *file_set.class.audio_mime_types then create_audio_derivatives(filename) when *file_set.class.video_mime_types then create_video_derivatives(filename) when *file_set.class.image_mime_types 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
35 36 37 38 |
# File 'app/services/hyrax/file_set_derivatives_service.rb', line 35 def derivative_url(destination_name) path = derivative_path_factory.derivative_path_for_reference(file_set, destination_name) URI("file://#{path}").to_s end |
#valid? ⇒ Boolean
19 20 21 |
# File 'app/services/hyrax/file_set_derivatives_service.rb', line 19 def valid? supported_mime_types.include?(mime_type) end |