diff --git a/lib/tasks/attachment_maintaining_service.rake b/lib/tasks/attachment_maintaining_service.rake index 6587edd4c8c5d01ee8f47c379fdbe34b4b06925d..6c95f7716e65dfb676bed42f6dadc37077b70911 100644 --- a/lib/tasks/attachment_maintaining_service.rake +++ b/lib/tasks/attachment_maintaining_service.rake @@ -1,25 +1,22 @@ require 'fileutils' namespace :attachment_maintaining_service do - desc 'Removing 10 attachments' + + desc 'Removing attachments' task remove_attachments: :environment do - m = sort_directories.first(10) - m.each do |mm| - #puts (mm) - FileUtils.rm_r(mm) + sort_directories.first(10).each do |dir| + FileUtils.rm_r(dir) end end + private + def sort_directories - files_sorted_by_time = Dir[dir_path].sort_by{ |f| File.atime(f) } - files_sorted_by_time + Dir[dir_path].sort_by{ |f| File.atime(f) } end - private - def dir_path - c = Rails.root.join('public','attachments','*').to_s - c + Rails.root.join('public','attachments','*').to_s end end