Commit c9834ef9 by Jon Yurek

Added new task for cleaning out invalid attachments.

parent 13895667
......@@ -203,6 +203,7 @@ module Paperclip
@styles.each do |name, args|
begin
dimensions, format = args
dimensions = dimensions.call(instance) if dimensions.respond_to? :call
@queued_for_write[name] = Thumbnail.make(@queued_for_write[:original],
dimensions,
format,
......
......@@ -14,19 +14,15 @@ def obtain_attachments
end
end
namespace :paperclip do
desc "Regenerates thumbnails for a given CLASS (and optional ATTACHMENT)"
task :refresh => :environment do
def for_all_attachments
klass = obtain_class
names = obtain_attachments
instances = klass.find(: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
yield(instance, name)
else
true
end
......@@ -34,5 +30,26 @@ namespace :paperclip do
end
end
puts " Done."
end
namespace :paperclip do
desc "Regenerates thumbnails for a given CLASS (and optional ATTACHMENT)"
task :refresh => :environment do
for_all_attachments do |instance, name|
instance.send(name).reprocess!
instance.send(name).save
end
end
desc "Cleans out invalid attachments. Useful after you've added new validations."
task :clean => :environment do
for_all_attachments do |instance, name|
if instance.valid?
true
else
instance.send("#{name}=", nil)
instance.save
end
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment