Sha256: ed81ff80e34a7aebf33104162b833e2f0d5e2db7cd18e3de2da00e7b094ddf7a
Contents?: true
Size: 1.93 KB
Versions: 1
Compression:
Stored size: 1.93 KB
Contents
module PaperclipCompression class Base def initialize(file, first_processor) @file = file current_extension = File.extname(file.path) @basename = File.basename(file.path, current_extension) @dst = Paperclip::TempfileFactory.new.generate("#{@basename}.png") @dst_path = File.expand_path(@dst.path) @src_path = File.expand_path(@file.path) @first_processor = first_processor end def self.make(file, first_processor, options = {}) new(file, first_processor, options).make end def process_file # Close output file so compressors which require exclusive file rights # work. @dst.close # Execute the child-compressor classes implementation of how to compress # the output compress # Re-open the output file so downstream paperclip-middleware may # read/write/etc. without having to re-open the file. @dst.open # Return the destination file for downstream paperclip processors. @dst end protected def process_file? @cli_opts end def unprocessed_tempfile copy_to_tempfile first_processor? ? @dst : @file end def command_path(command) folder = if OS.osx? 'osx' elsif OS.linux? File.join('linux', OS.bits.eql?(64) ? 'x64' : 'x86') elsif OS.windows? OS.bits.eql?(64) ? 'win64' : 'win32' end File.join(PaperclipCompression.root, 'bin', folder, command) end private def compress fail MustImplementInSubClassesException, 'compress is overridden on a per compressor basis.' end def first_processor? @first_processor end def copy_to_tempfile FileUtils.cp(@src_path, @dst_path) end end # Informs developers when a method is intended to be defined in # sub-classes. class MustImplementInSubClassesException < Exception; end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
paperclip-compression-1.0.0 | lib/paperclip-compression/base.rb |