Class: FileFinder

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

Instance Method Summary collapse

Constructor Details

#initialize(finder, dir) ⇒ FileFinder

Returns a new instance of FileFinder.



3
4
5
6
7
# File 'lib/file_finder.rb', line 3

def initialize(finder, dir)
  @finder = finder
  @dir = dir
  @filters = []
end

Instance Method Details

#add_filter(filter) ⇒ Object



9
10
11
# File 'lib/file_finder.rb', line 9

def add_filter(filter)
  @filters << filter
end

#findObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/file_finder.rb', line 13

def find
  
  # Refactor in detecting changes from previous all files list
  # Refactor in ability to ignore certain dirs/files (.svn etc)
  # Refactor detecting modified files
  
  all_files = []
  filtered_files = []

  @finder.find(@dir) do |path|
    all_files << path
    
    keep = @filters.inject(true) { |k, filter| k && filter.filter(path)  }
    filtered_files << path if keep
  end
  
  @filters.each do |filter|
    filter.complete
  end

  return { :all => all_files, :filtered => filtered_files }
end