Class: PaperclipCompression::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/paperclip-compression/base.rb

Direct Known Subclasses

Jpeg, Png

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, first_processor) ⇒ Base

Returns a new instance of Base.



4
5
6
7
8
9
10
11
12
# File 'lib/paperclip-compression/base.rb', line 4

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)
  @dst_path         = File.expand_path(@dst.path)
  @src_path         = File.expand_path(@file.path)
  @first_processor  = first_processor
end

Class Method Details

.make(file, first_processor, options = {}) ⇒ Object



14
15
16
# File 'lib/paperclip-compression/base.rb', line 14

def self.make(file, first_processor, options = {})
  new(file, first_processor, options).make
end

Instance Method Details

#process_fileObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/paperclip-compression/base.rb', line 18

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