Class: Hyrax::PersistDerivatives
- Inherits:
-
Hydra::Derivatives::PersistOutputFileService
- Object
- Hydra::Derivatives::PersistOutputFileService
- Hyrax::PersistDerivatives
- Defined in:
- app/services/hyrax/persist_derivatives.rb
Class Method Summary collapse
-
.call(stream, directives) ⇒ Object
Persists a derivative to the local file system.
- .derivative_path_factory ⇒ Object deprecated Deprecated.
-
.output_file(directives, &blk) ⇒ Object
Open the output file to write and yield the block to the file.
Class Method Details
.call(stream, directives) ⇒ Object
Persists a derivative to the local file system. This Service conforms to the signature of ‘Hydra::Derivatives::PersistOutputFileService`. This service is an alternative to the default Hydra::Derivatives::PersistOutputFileService. This service will always update existing and does not do versioning of persisted files.
12 13 14 15 16 |
# File 'app/services/hyrax/persist_derivatives.rb', line 12 def self.call(stream, directives) output_file(directives) do |output| IO.copy_stream(stream, output) end end |
.derivative_path_factory ⇒ Object
Deprecated.
31 32 33 34 |
# File 'app/services/hyrax/persist_derivatives.rb', line 31 def self.derivative_path_factory Deprecation.warn("Use 'Hyrax::DerivativePath' instead.") DerivativePath end |
.output_file(directives, &blk) ⇒ Object
Open the output file to write and yield the block to the file. It makes the directories in the path if necessary.
20 21 22 23 24 25 26 27 |
# File 'app/services/hyrax/persist_derivatives.rb', line 20 def self.output_file(directives, &blk) raise ArgumentError, "No :url was provided in the transcoding directives" unless directives.key?(:url) uri = URI(directives.fetch(:url)) raise ArgumentError, "Must provide a file uri" unless uri.scheme == 'file' output_file_dir = File.dirname(uri.path) FileUtils.mkdir_p(output_file_dir) unless File.directory?(output_file_dir) File.open(uri.path, 'wb', &blk) end |