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.
8 9 10 |
# File 'app/services/hyrax/file_set_derivatives_service.rb', line 8 def initialize(file_set) @file_set = file_set end |
Instance Attribute Details
#file_set ⇒ Object (readonly)
Returns the value of attribute file_set.
4 5 6 |
# File 'app/services/hyrax/file_set_derivatives_service.rb', line 4 def file_set @file_set end |
Instance Method Details
#cleanup_derivatives ⇒ Object
12 13 14 15 16 |
# File 'app/services/hyrax/file_set_derivatives_service.rb', line 12 def cleanup_derivatives derivative_path_factory.derivatives_for_reference(file_set).each do |path| FileUtils.rm_f(path) end end |
#create_derivatives(filename) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'app/services/hyrax/file_set_derivatives_service.rb', line 22 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
34 35 36 37 |
# File 'app/services/hyrax/file_set_derivatives_service.rb', line 34 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
18 19 20 |
# File 'app/services/hyrax/file_set_derivatives_service.rb', line 18 def valid? supported_mime_types.include?(mime_type) end |