Commit a3bfeb11 by Matthew Mongeau

@klass is no longer used in rake task. obtain_class should return the class name.

parent e246cfbd
def obtain_class def obtain_class
class_name = ENV['CLASS'] || ENV['class'] class_name = ENV['CLASS'] || ENV['class']
raise "Must specify CLASS" unless class_name raise "Must specify CLASS" unless class_name
class_name
end end
def obtain_attachments def obtain_attachments(klass)
klass = Object.const_get(klass.to_s)
name = ENV['ATTACHMENT'] || ENV['attachment'] name = ENV['ATTACHMENT'] || ENV['attachment']
raise "Class #{@klass.name} has no attachments specified" unless @klass.respond_to?(:attachment_definitions) raise "Class #{klass.name} has no attachments specified" unless klass.respond_to?(:attachment_definitions)
if !name.blank? && @klass.attachment_definitions.keys.include?(name) if !name.blank? && klass.attachment_definitions.keys.include?(name)
[ name ] [ name ]
else else
@klass.attachment_definitions.keys klass.attachment_definitions.keys
end end
end end
...@@ -21,8 +23,8 @@ namespace :paperclip do ...@@ -21,8 +23,8 @@ namespace :paperclip do
desc "Regenerates thumbnails for a given CLASS (and optional ATTACHMENT)." desc "Regenerates thumbnails for a given CLASS (and optional ATTACHMENT)."
task :thumbnails => :environment do task :thumbnails => :environment do
errors = [] errors = []
names = obtain_attachments
klass = obtain_class klass = obtain_class
names = obtain_attachments(klass)
names.each do |name| names.each do |name|
Paperclip.each_instance_with_attachment(klass, name) do |instance| Paperclip.each_instance_with_attachment(klass, name) do |instance|
result = instance.send(name).reprocess! result = instance.send(name).reprocess!
...@@ -34,8 +36,8 @@ namespace :paperclip do ...@@ -34,8 +36,8 @@ namespace :paperclip do
desc "Regenerates content_type/size metadata for a given CLASS (and optional ATTACHMENT)." desc "Regenerates content_type/size metadata for a given CLASS (and optional ATTACHMENT)."
task :metadata => :environment do task :metadata => :environment do
names = obtain_attachments
klass = obtain_class klass = obtain_class
names = obtain_attachments(klass)
names.each do |name| names.each do |name|
Paperclip.each_instance_with_attachment(klass, name) do |instance| Paperclip.each_instance_with_attachment(klass, name) do |instance|
if file = instance.send(name).to_file if file = instance.send(name).to_file
...@@ -53,8 +55,8 @@ namespace :paperclip do ...@@ -53,8 +55,8 @@ namespace :paperclip do
desc "Cleans out invalid attachments. Useful after you've added new validations." desc "Cleans out invalid attachments. Useful after you've added new validations."
task :clean => :environment do task :clean => :environment do
names = obtain_attachments
klass = obtain_class klass = obtain_class
names = obtain_attachments(klass)
names.each do |name| names.each do |name|
Paperclip.each_instance_with_attachment(klass, name) do |instance| Paperclip.each_instance_with_attachment(klass, name) do |instance|
instance.send(name).send(:validate) instance.send(name).send(:validate)
......
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