lib/file_crawler.rb in fde-file_crawler-0.1.1 vs lib/file_crawler.rb in fde-file_crawler-0.2.0
- old
+ new
@@ -1,7 +1,6 @@
require 'file_crawler/version'
-require 'file_crawler/crawler'
module FDE
module FileCrawler
class Config
@@ -12,8 +11,39 @@
@@config ||= Config.new
end
def self.configure
yield self.config
+ end
+
+ def self.watch(query = nil, &block)
+ unless query.nil?
+ yield self.crawl(query)
+ else
+ yield self.crawl
+ end
+ end
+
+ def self.crawl(query = /.*\.*/i)
+ path = self.config.path_to_directory
+ files = Dir.entries(path)
+ files -= %w[. ..]
+ files.select { |file| query.match(file) }
+ end
+
+ def self.copy(file, target)
+ FileUtils.copy(path_for(file), target)
+ end
+
+ def self.delete(file)
+ FileUtils.rm(path_for(file))
+ end
+
+ def self.move(file, target)
+ FileUtils.mv(path_for(file), target)
+ end
+
+ def self.path_for(file)
+ "#{self.config.path_to_directory}#{file}"
end
end
end