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,25 +14,42 @@ def obtain_attachments
end
end
def for_all_attachments
klass = obtain_class
names = obtain_attachments
instances = klass.find(:all)
instances.each do |instance|
names.each do |name|
result = if instance.send("#{ name }?")
yield(instance, name)
else
true
end
print result ? "." : "x"; $stdout.flush
end
end
puts " Done."
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.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
else
true
end
print result ? "." : "x"; $stdout.flush
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
puts " Done."
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