jamis-fuzzy_file_finder 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,10 @@
1
1
 
2
- # Gem::Specification for Fuzzy_file_finder-1.0.3
2
+ # Gem::Specification for Fuzzy_file_finder-1.0.4
3
3
  # Originally generated by Echoe
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = %q{fuzzy_file_finder}
7
- s.version = "1.0.3"
7
+ s.version = "1.0.4"
8
8
 
9
9
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
10
  s.authors = ["Jamis Buck"]
@@ -37,7 +37,7 @@ class FuzzyFileFinder
37
37
  module Version
38
38
  MAJOR = 1
39
39
  MINOR = 0
40
- TINY = 3
40
+ TINY = 4
41
41
  STRING = [MAJOR, MINOR, TINY].join(".")
42
42
  end
43
43
 
@@ -102,11 +102,14 @@ class FuzzyFileFinder
102
102
  # The prefix shared by all +roots+.
103
103
  attr_reader :shared_prefix
104
104
 
105
+ # The list of glob patterns to ignore.
106
+ attr_reader :ignores
107
+
105
108
  # Initializes a new FuzzyFileFinder. This will scan the
106
109
  # given +directories+, using +ceiling+ as the maximum number
107
110
  # of entries to scan. If there are more than +ceiling+ entries
108
111
  # a TooManyEntries exception will be raised.
109
- def initialize(directories=['.'], ceiling=10_000)
112
+ def initialize(directories=['.'], ceiling=10_000, ignores=nil)
110
113
  directories = Array(directories)
111
114
  directories << "." if directories.empty?
112
115
 
@@ -120,6 +123,8 @@ class FuzzyFileFinder
120
123
  @files = []
121
124
  @ceiling = ceiling
122
125
 
126
+ @ignores = Array(ignores)
127
+
123
128
  rescan!
124
129
  end
125
130
 
@@ -218,12 +223,18 @@ class FuzzyFileFinder
218
223
 
219
224
  if File.directory?(full)
220
225
  follow_tree(Directory.new(full))
221
- else
226
+ elsif !ignore?(full.sub(@shared_prefix_re, ""))
222
227
  files.push(FileSystemEntry.new(directory, entry))
223
228
  end
224
229
  end
225
230
  end
226
231
 
232
+ # Returns +true+ if the given name matches any of the ignore
233
+ # patterns.
234
+ def ignore?(name)
235
+ ignores.any? { |pattern| File.fnmatch(pattern, name) }
236
+ end
237
+
227
238
  # Takes the given pattern string "foo" and converts it to a new
228
239
  # string "(f)([^/]*?)(o)([^/]*?)(o)" that can be used to create
229
240
  # a regular expression.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jamis-fuzzy_file_finder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamis Buck