Module: FDE::FileCrawler

Defined in:
lib/fde/file_crawler.rb,
lib/fde/file_crawler/version.rb

Defined Under Namespace

Classes: Config, NoCopyTargetDefined

Constant Summary collapse

VERSION =
"0.6.0"

Class Method Summary collapse

Class Method Details

.configObject



13
14
15
# File 'lib/fde/file_crawler.rb', line 13

def self.config
  @@config ||= Config.new
end

.configure {|self.config| ... } ⇒ Object

Yields:



17
18
19
# File 'lib/fde/file_crawler.rb', line 17

def self.configure
  yield self.config
end

.copy(file, target = nil) ⇒ Object



34
35
36
37
38
39
40
41
42
# 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) ⇒ Object



27
28
29
30
31
32
# 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) ⇒ Object



44
45
46
# File 'lib/fde/file_crawler.rb', line 44

def self.delete(file)
  FileUtils.rm(path_for(file))
end

.move(file, target) ⇒ Object



48
49
50
# File 'lib/fde/file_crawler.rb', line 48

def self.move(file, target)
  FileUtils.mv(path_for(file), target)
end

.path_for(file) ⇒ Object



52
53
54
# File 'lib/fde/file_crawler.rb', line 52

def self.path_for(file)
  "#{self.config.path_in_directory}#{file}"
end

.watch(query = /.*\.*/i, &block) ⇒ Object



21
22
23
24
25
# File 'lib/fde/file_crawler.rb', line 21

def self.watch(query = /.*\.*/i, &block)
  self.crawl(query).each do |file|
    yield file
  end
end