class BPL::Derivatives::PersistFileSystemOutputService
Public Class Methods
call(object, directives)
click to toggle source
# File lib/bpl/derivatives/services/persist_file_system_output_service.rb, line 3 def self.call(object, directives) filename = determine_original_name(object.content) write_file(object.content, directives, filename) end
determine_original_name(file)
click to toggle source
@param file [Hydra::Derivatives::IoDecorator]
# File lib/bpl/derivatives/services/persist_file_system_output_service.rb, line 9 def self.determine_original_name(file) if file.respond_to? :original_filename file.original_filename else "derivative" end end
Private Class Methods
write_file(content, directives, filename)
click to toggle source
# File lib/bpl/derivatives/services/persist_file_system_output_service.rb, line 17 def self.write_file(content, directives, filename) path = directives.fetch(:path) fmt = directives.fetch(:format) full_file_name = File.join(path, "#{filename}.#{fmt}") raise ArgumentError, "path directive is blank" if path.blank? raise ArgumentError, "format directive is blank" if fmt.blank? File.open(full_file_name, "w+") do |f| f.write(content) end end