Skip to content

Commit

Permalink
@klass is no longer used in rake task. obtain_class should return the…
Browse files Browse the repository at this point in the history
… class name.
  • Loading branch information
halogenandtoast committed Dec 14, 2010
1 parent e246cfb commit a3bfeb1
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/tasks/paperclip.rake
@@ -1,15 +1,17 @@
def obtain_class
class_name = ENV['CLASS'] || ENV['class']
raise "Must specify CLASS" unless class_name
class_name
end

def obtain_attachments
def obtain_attachments(klass)
klass = Object.const_get(klass.to_s)
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)
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
klass.attachment_definitions.keys
end
end

Expand All @@ -21,8 +23,8 @@ namespace :paperclip do
desc "Regenerates thumbnails for a given CLASS (and optional ATTACHMENT)."
task :thumbnails => :environment do
errors = []
names = obtain_attachments
klass = obtain_class
names = obtain_attachments(klass)
names.each do |name|
Paperclip.each_instance_with_attachment(klass, name) do |instance|
result = instance.send(name).reprocess!
Expand All @@ -34,8 +36,8 @@ namespace :paperclip do

desc "Regenerates content_type/size metadata for a given CLASS (and optional ATTACHMENT)."
task :metadata => :environment do
names = obtain_attachments
klass = obtain_class
names = obtain_attachments(klass)
names.each do |name|
Paperclip.each_instance_with_attachment(klass, name) do |instance|
if file = instance.send(name).to_file
Expand All @@ -53,8 +55,8 @@ namespace :paperclip do

desc "Cleans out invalid attachments. Useful after you've added new validations."
task :clean => :environment do
names = obtain_attachments
klass = obtain_class
names = obtain_attachments(klass)
names.each do |name|
Paperclip.each_instance_with_attachment(klass, name) do |instance|
instance.send(name).send(:validate)
Expand Down

0 comments on commit a3bfeb1

Please sign in to comment.