Module: CarrierWave::Uploader::Processing::ClassMethods

Defined in:
lib/carrierwave/uploader/processing.rb

Instance Method Summary collapse

Instance Method Details

#process(*args) ⇒ Object

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=> Array[])

Examples

class MyUploader < CarrierWave::Uploader::Base

  process :sepiatone, :vignette
  process :scale => [200, 200]
  process :scale => [200, 200], :if => :image?
  process :sepiatone, :if => :image?

  def sepiatone
    ...
  end

  def vignette
    ...
  end

  def scale(height, width)
    ...
  end

  def image?
    ...
  end

end


56
57
58
59
60
61
62
63
64
65
66
# File 'lib/carrierwave/uploader/processing.rb', line 56

def process(*args)
  new_processors = args.inject({}) do |hash, arg|
    arg = { arg => [] } unless arg.is_a?(Hash)
    hash.merge!(arg)
  end

  condition = new_processors.delete(:if)
  new_processors.each do |processor, processor_args|
    self.processors += [[processor, processor_args, condition]]
  end
end