Class: TreeRb::DirProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/tree_rb/input_plugins/file_system/dir_processor.rb

Overview

Visit a directory tree not TreeNode related

Instance Method Summary collapse

Constructor Details

#initialize(&action) ⇒ DirProcessor

Returns a new instance of DirProcessor.



10
11
12
13
# File 'lib/tree_rb/input_plugins/file_system/dir_processor.rb', line 10

def initialize( &action )
  @processors = {}
  @default_processor = action
end

Instance Method Details

#add_processor(re, &action) ⇒ Object



15
16
17
# File 'lib/tree_rb/input_plugins/file_system/dir_processor.rb', line 15

def add_processor( re, &action )
  @processors[ re ] = action
end

#process(dirname) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/tree_rb/input_plugins/file_system/dir_processor.rb', line 19

def process( dirname )
  @dirname = dirname
  old_dirname = Dir.pwd
  Dir.chdir( @dirname )
  Dir['**/*'].each { |f|
    pn = Pathname.new( f ).expand_path
    # puts "#{self.class.name}#loadfromdir #{f}"
    next if pn.directory?
    process_file( pn )
  }
  Dir.chdir( old_dirname )
  self
end