module FDE::FileCrawler

Constants

VERSION

Public Class Methods

config() click to toggle source
# File lib/fde/file_crawler.rb, line 13
def self.config
  @@config ||= Config.new
end
configure() { |config| ... } click to toggle source
# File lib/fde/file_crawler.rb, line 17
def self.configure
  yield self.config
end
copy(file, target = nil) click to toggle source
# File lib/fde/file_crawler.rb, line 34
def self.copy(file, target = nil)
  if self.config.path_out_directory && target.nil?
    FileUtils.copy(path_for(file), self.config.path_out_directory)
  elsif target.nil?
    raise NoCopyTargetDefined
  else
    FileUtils.copy(path_for(file), target)
  end
end
crawl(query = /.*\.*/i) click to toggle source
# File lib/fde/file_crawler.rb, line 27
def self.crawl(query = /.*\.*/i)
  path = self.config.path_in_directory
  files = Dir.entries(path)
  files -=  %w[. ..]
  files.select { |file| query.match(file) }
end
delete(file) click to toggle source
# File lib/fde/file_crawler.rb, line 44
def self.delete(file)
  FileUtils.rm(path_for(file))
end
move(file, target) click to toggle source
# File lib/fde/file_crawler.rb, line 48
def self.move(file, target)
  FileUtils.mv(path_for(file), target)
end
path_for(file) click to toggle source
# File lib/fde/file_crawler.rb, line 52
def self.path_for(file)
  "#{self.config.path_in_directory}#{file}"
end
watch(query = /.*\.*/i) { |file| ... } click to toggle source
# File lib/fde/file_crawler.rb, line 21
def self.watch(query = /.*\.*/i, &block)
  self.crawl(query).each do |file|
    yield file
  end
end