Sha256: 5106215a7ec5de148e3e7946f31d707e5c7fed7763d835a50027824f4746b32c

Contents?: true

Size: 1.98 KB

Versions: 13

Compression:

Stored size: 1.98 KB

Contents

# encoding: utf-8

module CarrierWave
  module Uploader
    module Processing

      depends_on CarrierWave::Uploader::Callbacks

      setup do
        after :cache, :process!
      end

      module ClassMethods

        ##
        # Lists processor callbacks declared
        #
        # === Returns
        #
        # [Array[Array[Symbol, Array]]] a list of processor callbacks which have been declared for this uploader
        #
        def processors
          @processors ||= []
        end

        ##
        # Adds a processor callback which applies operations as a file is uploaded.
        # The argument may be the name of any method of the uploader, expressed as a symbol,
        # or a list of such methods, or a hash where the key is a method and the value is
        # an array of arguments to call the method with
        #
        # === Parameters
        #
        # args (*Symbol, Hash{Symbol => Array[]})
        #
        # === Examples
        #
        #     class MyUploader < CarrierWave::Uploader::Base
        #
        #       process :sepiatone, :vignette
        #       process :scale => [200, 200]
        #
        #       def sepiatone
        #         ...
        #       end
        #
        #       def vignette
        #         ...
        #       end
        #
        #       def scale(height, width)
        #         ...
        #       end
        #     end
        #
        def process(*args)
          args.each do |arg|
            if arg.is_a?(Hash)
              arg.each do |method, args|
                processors.push([method, args])
              end
            else
              processors.push([arg, []])
            end
          end
        end

      end # ClassMethods

      ##
      # Apply all process callbacks added through CarrierWave.process
      #
      def process!(new_file=nil)
        self.class.processors.each do |method, args|
          self.send(method, *args)
        end
      end

    end # Processing
  end # Uploader
end # CarrierWave

Version data entries

13 entries across 13 versions & 4 rubygems

Version Path
andrewtimberlake-carrierwave-0.3.2.1 lib/carrierwave/uploader/processing.rb
durran-carrierwave-0.3.2.3 lib/carrierwave/uploader/processing.rb
jnicklas-carrierwave-0.3.2.1 lib/carrierwave/uploader/processing.rb
jnicklas-carrierwave-0.3.2 lib/carrierwave/uploader/processing.rb
jnicklas-carrierwave-0.3.3 lib/carrierwave/uploader/processing.rb
carrierwave-0.4.1 lib/carrierwave/uploader/processing.rb
carrierwave-0.4.0 lib/carrierwave/uploader/processing.rb
carrierwave-0.3.5.2 lib/carrierwave/uploader/processing.rb
carrierwave-0.3.5.1 lib/carrierwave/uploader/processing.rb
carrierwave-0.3.5 lib/carrierwave/uploader/processing.rb
carrierwave-0.3.4 lib/carrierwave/uploader/processing.rb
carrierwave-0.3.3 lib/carrierwave/uploader/processing.rb
carrierwave-0.3.2 lib/carrierwave/uploader/processing.rb