Sha256: 968d2f6f06fad3b0ff571de252c05014afc538d24c603b89bcf15d7703f6f5df

Contents?: true

Size: 1.87 KB

Versions: 15

Compression:

Stored size: 1.87 KB

Contents

module Paperclip
  # Paperclip processors allow you to modify attached files when they are
  # attached in any way you are able. Paperclip itself uses command-line
  # programs for its included Thumbnail processor, but custom processors
  # are not required to follow suit.
  #
  # Processors are required to be defined inside the Paperclip module and
  # are also required to be a subclass of Paperclip::Processor. There are
  # only two methods you must implement to properly be a subclass: 
  # #initialize and #make. Initialize's arguments are the file that will
  # be operated on (which is an instance of File), and a hash of options
  # that were defined in has_attached_file's style hash.
  #
  # All #make needs to do is return an instance of File (Tempfile is
  # acceptable) which contains the results of the processing.
  #
  # See Paperclip.run for more information about using command-line
  # utilities from within Processors.
  class Processor
    attr_accessor :file, :options, :attachment

    def initialize file, options = {}, attachment = nil
      @file = file
      @options = options
      @attachment = attachment
    end

    def make
    end

    def self.make file, options = {}, attachment = nil
      new(file, options, attachment).make
    end
  end
  
  # Due to how ImageMagick handles its image format conversion and how Tempfile
  # handles its naming scheme, it is necessary to override how Tempfile makes
  # its names so as to allow for file extensions. Idea taken from the comments
  # on this blog post:
  # http://marsorange.com/archives/of-mogrify-ruby-tempfile-dynamic-class-definitions
  class Tempfile < ::Tempfile
    # Replaces Tempfile's +make_tmpname+ with one that honors file extensions.
    def make_tmpname(basename, n)
      extension = File.extname(basename)
      sprintf("%s,%d,%d%s", File.basename(basename, extension), $$, n, extension)
    end
  end
end

Version data entries

15 entries across 15 versions & 6 rubygems

Version Path
beaucollins-paperclip-2.2.7 lib/paperclip/processor.rb
betelgeuse-paperclip-2.2.8.1 lib/paperclip/processor.rb
fermion-paperclip-2.2.8 lib/paperclip/processor.rb
lostboy-paperclip-2.2.6.1 lib/paperclip/processor.rb
lostboy-paperclip-2.2.6.2 lib/paperclip/processor.rb
thoughtbot-paperclip-2.2.4 lib/paperclip/processor.rb
thoughtbot-paperclip-2.2.5 lib/paperclip/processor.rb
thoughtbot-paperclip-2.2.6 lib/paperclip/processor.rb
thoughtbot-paperclip-2.2.7 lib/paperclip/processor.rb
thoughtbot-paperclip-2.2.8 lib/paperclip/processor.rb
paperclip-2.2.4 lib/paperclip/processor.rb
paperclip-2.2.5 lib/paperclip/processor.rb
paperclip-2.2.6 lib/paperclip/processor.rb
paperclip-2.2.7 lib/paperclip/processor.rb
paperclip-2.2.8 lib/paperclip/processor.rb