Sha256: c06f7e4f6629b6b7c9fe0ef4f6ccc28f63eaad6a403a7d8ffe62b17942281b6b

Contents?: true

Size: 1.08 KB

Versions: 19

Compression:

Stored size: 1.08 KB

Contents

def obtain_class
  class_name = ENV['CLASS'] || ENV['class']
  raise "Must specify CLASS" unless class_name
  @klass = Object.const_get(class_name)
end

def obtain_attachments
  name = ENV['ATTACHMENT'] || ENV['attachment']
  raise "Class #{@klass.name} has no attachments specified" unless @klass.respond_to?(:attachment_definitions)
  if !name.blank? && @klass.attachment_definitions.keys.include?(name)
    [ name ]
  else
    @klass.attachment_definitions.keys
  end
end

namespace :paperclip do
  desc "Regenerates thumbnails for a given CLASS (and optional ATTACHMENT)"
  task :refresh => :environment do
    klass     = obtain_class
    names     = obtain_attachments
    instances = klass.all

    puts "Regenerating thumbnails for #{instances.length} instances of #{klass.name}:"
    instances.each do |instance|
      names.each do |name|
        result = if instance.send("#{ name }?")
          instance.send(name).reprocess!
          instance.send(name).save
        else
          true
        end
        print result ? "." : "x"; $stdout.flush
      end
    end
    puts " Done."
  end
end

Version data entries

19 entries across 19 versions & 3 rubygems

Version Path
dm-paperclip-2.5.0 tasks/paperclip_tasks.rake
dm-paperclip-r3-2.4.5 tasks/paperclip_tasks.rake
ripta-dm-paperclip-2.6.2.1 tasks/paperclip_tasks.rake
ripta-dm-paperclip-2.6.1 tasks/paperclip_tasks.rake
ripta-dm-paperclip-2.5.1 tasks/paperclip_tasks.rake
dm-paperclip-r3-2.4.4 tasks/paperclip_tasks.rake
dm-paperclip-r3-2.4.3 tasks/paperclip_tasks.rake
dm-paperclip-r3-2.4.2 tasks/paperclip_tasks.rake
dm-paperclip-r3-2.4.1 tasks/paperclip_tasks.rake
ripta-dm-paperclip-2.5.0.2 tasks/paperclip_tasks.rake
ripta-dm-paperclip-2.5.0.1 tasks/paperclip_tasks.rake
dm-paperclip-2.4.1 tasks/paperclip_tasks.rake
dm-paperclip-2.4.0 tasks/paperclip_tasks.rake
dm-paperclip-2.3.1 tasks/paperclip_tasks.rake
dm-paperclip-2.3.0 tasks/paperclip_tasks.rake
ripta-dm-paperclip-2.2.9.2 tasks/paperclip_tasks.rake
dm-paperclip-2.1.2.1 tasks/paperclip_tasks.rake
dm-paperclip-2.1.2 tasks/paperclip_tasks.rake
dm-paperclip-2.1.4 tasks/paperclip_tasks.rake