Module: Search
- Defined in:
- lib/shed/search.rb
Overview
Collection of methods for searching directories.
Class Method Summary collapse
-
.find_all(files_of_type, dir, excluding = []) ⇒ Object
Searches a directory and it’s child directories for all the files whose names match the specified regular expression.
-
.for_empties(dir, excluding = ['.svn','.git']) ⇒ Object
Scans the path and its children for empty directories.
Class Method Details
.find_all(files_of_type, dir, excluding = []) ⇒ Object
Searches a directory and it’s child directories for all the files whose names match the specified regular expression.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/shed/search.rb', line 14 def self.find_all(files_of_type,dir,excluding=[]) Find.find(dir) do |path| if FileTest.directory?(path) if excluding.include?(File.basename(path)) Find.prune else next end elsif File.extname(path) =~ files_of_type yield path end end end |
.for_empties(dir, excluding = ['.svn','.git']) ⇒ Object
Scans the path and its children for empty directories.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/shed/search.rb', line 34 def self.for_empties(dir,excluding=['.svn','.git']) Find.find(dir) do |path| if FileTest.directory?(path) if excluding.include?(File.basename(path)) Find.prune else # Any dir that only contains ., .., and .svn or .git are empty. yield path if Dir.entries(path).join =~ /^\.\.\.(\.(svn|git))?$/ end end end end |