Commit 201c84ba by Jon Yurek

Added paperclip:refresh:metadata and :thumbnails tasks, and a paperclip:refresh…

Added paperclip:refresh:metadata and :thumbnails tasks, and a paperclip:refresh task to tie them together. Also, paperclip:clean checks validity of the attachment, not the whole model instance.
parent b651d081
......@@ -33,11 +33,28 @@ def for_all_attachments
end
namespace :paperclip do
desc "Regenerates thumbnails for a given CLASS (and optional ATTACHMENT)"
task :refresh => :environment do
desc "Refreshes both metadata and thumbnails."
task :refresh => ["paperclip:refresh:metadata", "paperclip:refresh:thumbnails"]
namespace :refresh do
desc "Regenerates thumbnails for a given CLASS (and optional ATTACHMENT)."
task :thumbnails => :environment do
for_all_attachments do |instance, name|
instance.send(name).reprocess!
instance.send(name).save
end
end
desc "Regenerates content_type/size metadata for a given CLASS (and optional ATTACHMENT)."
task :metadata => :environment do
for_all_attachments do |instance, name|
if file = instance.send(name).to_file
instance.send("#{name}_content_type=", file.content_type)
instance.send("#{name}_file_size=", file.size)
instance.save(false)
else
true
end
end
end
end
......@@ -45,7 +62,7 @@ namespace :paperclip do
task :clean => :environment do
for_all_attachments do |instance, name|
instance.send(name).send(:validate)
if instance.valid?
if instance.send(name).valid?
true
else
instance.send("#{name}=", nil)
......
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