class BPL::Derivatives::TempfileService
Attributes
source_file[R]
source_object[R]
Public Class Methods
create(object, &block)
click to toggle source
# File lib/bpl/derivatives/services/tempfile_service.rb, line 5 def self.create(object, &block) new(object).tempfile(&block) end
new(source_object)
click to toggle source
# File lib/bpl/derivatives/services/tempfile_service.rb, line 11 def initialize(source_object) @source_object = source_object @source_file = nil end
Public Instance Methods
default_tempfile() { |f| ... }
click to toggle source
# File lib/bpl/derivatives/services/tempfile_service.rb, line 32 def default_tempfile(&_block) Tempfile.open(filename_for_characterization) do |f| f.binmode if source_file.content.respond_to? :read f.write(source_file.content.read) else f.write(source_file.content) end source_file.content.rewind if source_file.content.respond_to? :rewind f.rewind yield(f) end end
tempfile(&block)
click to toggle source
# File lib/bpl/derivatives/services/tempfile_service.rb, line 24 def tempfile(&block) if source_file.respond_to? :to_tempfile source_file.send(:to_tempfile, &block) elsif source_file.has_content? default_tempfile(&block) end end
Protected Instance Methods
default_filename_for_characterization()
click to toggle source
# File lib/bpl/derivatives/services/tempfile_service.rb, line 56 def default_filename_for_characterization registered_mime_type = MIME::Types[source_file.mime_type].first BPL::Derivatives.base_logger.warn "Unable to find a registered mime type for #{source_file.mime_type.inspect} on #{source_object.uri}" unless registered_mime_type extension = registered_mime_type ? ".#{registered_mime_type.extensions.first}" : '' version_id = 1 # TODO: fixme m = %r{/([^/]*)$}.match(source_object.uri) ["#{m[1]}-#{version_id}", extension.to_s] end
filename_for_characterization()
click to toggle source
# File lib/bpl/derivatives/services/tempfile_service.rb, line 48 def filename_for_characterization if source_file.respond_to? :filename_for_characterization source_file.filename_for_characterization else default_filename_for_characterization end end