lib/terragov/cleaner.rb in terragov-0.2.3 vs lib/terragov/cleaner.rb in terragov-0.2.4

- old
+ new

@@ -1,30 +1,34 @@ require 'find' require 'highline' module Terragov class Cleaner - def delete(path, pattern, force=false) - files = Find.find(path).grep(pattern) + def delete(path, patterns = [], force = false) + patterns.each do |pattern| + puts path - if files.empty? - puts "No files found matching #{pattern} in #{path}" - exit - end + files = Find.find(path).grep(pattern) - puts "Files matching #{pattern} found:" + if files.empty? + puts "No files found matching #{pattern} in #{path}" + next + end - files.each do |file| - puts File.expand_path(file) - end + puts "Files matching #{pattern} found:" - unless force - exit unless HighLine.agree('Do you wish to delete?') - end + files.each do |file| + puts File.expand_path(file) + end - files.each do |file| - File.delete(File.expand_path(file)) + unless force + next unless HighLine.agree('Do you wish to delete?') + end + + files.each do |file| + File.delete(File.expand_path(file)) + end + puts 'Done' end - puts "Done" end end end