Class: Peaches::Finder
- Inherits:
-
Object
- Object
- Peaches::Finder
- Defined in:
- lib/peaches/finder.rb
Instance Attribute Summary collapse
-
#cache ⇒ Object
Get and/or fetch the file list cache.
Instance Method Summary collapse
-
#build_cache ⇒ Object
Builds the cache excluding files that start with .
-
#find(string) ⇒ Object
FuzzyFind files from the cache.
-
#initialize(root) ⇒ Finder
constructor
Init.
-
#refresh_cache ⇒ Object
forces a refresh of the file list cache.
Constructor Details
Instance Attribute Details
#cache ⇒ Object
Get and/or fetch the file list cache
35 36 37 |
# File 'lib/peaches/finder.rb', line 35 def cache @cache end |
Instance Method Details
#build_cache ⇒ Object
Builds the cache excluding files that start with .
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/peaches/finder.rb', line 40 def build_cache all_files = [] Find.find(@root) do |path| if FileTest.directory?(path) if File.basename(path)[0] == ?. Find.prune else next end else path.slice!("#{@root}/") all_files << path end end return all_files end |
#find(string) ⇒ Object
FuzzyFind files from the cache
Paarameters
- string
-
The string you want to use to find matching files, if left black it will bring up all the files
20 21 22 23 24 25 26 27 |
# File 'lib/peaches/finder.rb', line 20 def find(string) string = string.split(//).join(".*?") pattern = "/#{string}/i" results = self.cache.grep /#{string}/i return results end |
#refresh_cache ⇒ Object
forces a refresh of the file list cache
30 31 32 |
# File 'lib/peaches/finder.rb', line 30 def refresh_cache @cache = build_cache end |