Module: CarrierWave::Uploader::Versions::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#recursively_apply_block_to_versions(&block) ⇒ Object


67
68
69
70
71
72
# File 'lib/carrierwave/uploader/versions.rb', line 67

def recursively_apply_block_to_versions(&block)
  versions.each do |name, version|
    version.class_eval(&block)
    version.recursively_apply_block_to_versions(&block)
  end
end

#version(name, options = {}, &block) ⇒ Object

Adds a new version to this uploader

Parameters

name (#to_sym)

name of the version

options (Hash)

optional options hash

&block (Proc)

a block to eval on this version of the uploader

Examples

class MyUploader < CarrierWave::Uploader::Base

  version :thumb do
    process :scale => [200, 200]
  end

  version :preview, :if => :image? do
    process :scale => [200, 200]
  end

  version :square, :unless => :invalid_image_type? do
    process :scale => [100, 100]
  end

end

59
60
61
62
63
64
65
# File 'lib/carrierwave/uploader/versions.rb', line 59

def version(name, options = {}, &block)
  name = name.to_sym
  build_version(name, options)

  versions[name].class_eval(&block) if block
  versions[name]
end