Module: FileCrawler::Finder::Command::Search

Included in:
FileCrawler::Finder
Defined in:
lib/file_crawler/finder/command/search.rb

Instance Method Summary collapse

Instance Method Details

#find_files_in_path(path) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/file_crawler/finder/command/search.rb', line 30

def find_files_in_path(path)
  Dir.entries(path).select {|item|
    !item.start_with?('.')
  }.map {|item|
    path + '/' + item
  }
end

#search(path, conditions = {}) ⇒ Object



6
7
8
9
10
# File 'lib/file_crawler/finder/command/search.rb', line 6

def search(path, conditions = {})
  tap {
    @rows = search_directories(path)
  }
end

#search_directories(path) ⇒ Object



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

def search_directories(path)
  directories = search_directories_in_path(path)
  return [path] if directories.empty?

  result = []
  directories.each {|item|
    result += search_directories(item)
  }

  result
end

#search_directories_in_path(path) ⇒ Object



24
25
26
27
28
# File 'lib/file_crawler/finder/command/search.rb', line 24

def search_directories_in_path(path)
  find_files_in_path(path).select {|item|
    File.directory?(item)
  }
end