Class: DirectoryTraverser

Inherits:
Object
  • Object
show all
Defined in:
lib/directory_traverser.rb

Instance Method Summary collapse

Constructor Details

#initialize(command, include = /.*/, verbose = false, out = $stdout, err = $stderr) ⇒ DirectoryTraverser

Returns a new instance of DirectoryTraverser.



4
5
6
7
8
9
10
# File 'lib/directory_traverser.rb', line 4

def initialize command, include=/.*/, verbose=false, out=$stdout, err=$stderr
  @command = command
  @include = include
  @verbose = verbose
  @out = out
  @err = err
end

Instance Method Details

#process(*paths, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/directory_traverser.rb', line 12

def process *paths, &block
  paths.each do |path|
    if FileTest.directory? path
      process_dir path, &block
    elsif FileTest.file? path
      process_file path, &block unless path.match(@include).nil? # only process file if it matches @include
    else
      raise "#{path} must be a directory or file"
    end
  end
end