jamis-fuzzy_file_finder 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/fuzzy_file_finder.gemspec +26 -3
- data/lib/fuzzy_file_finder.rb +22 -12
- metadata +2 -2
data/fuzzy_file_finder.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
|
2
|
-
# Gem::Specification for Fuzzy_file_finder-1.0.
|
2
|
+
# Gem::Specification for Fuzzy_file_finder-1.0.1
|
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.
|
7
|
+
s.version = "1.0.1"
|
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"]
|
11
|
-
s.date = %q{2008-10-
|
11
|
+
s.date = %q{2008-10-11}
|
12
12
|
s.description = %q{an implementation of TextMate's cmd-T search functionality}
|
13
13
|
s.email = %q{jamis@jamisbuck.org}
|
14
14
|
s.extra_rdoc_files = ["lib/fuzzy_file_finder.rb", "README.rdoc"]
|
@@ -31,3 +31,26 @@ Gem::Specification.new do |s|
|
|
31
31
|
else
|
32
32
|
end
|
33
33
|
end
|
34
|
+
|
35
|
+
|
36
|
+
# # Original Rakefile source (requires the Echoe gem):
|
37
|
+
#
|
38
|
+
# begin
|
39
|
+
# require 'echoe'
|
40
|
+
# rescue LoadError
|
41
|
+
# abort "You'll need to have `echoe' installed to use Net::SSH's Rakefile"
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# require './lib/fuzzy_file_finder'
|
45
|
+
# version = FuzzyFileFinder::Version::STRING.dup
|
46
|
+
# if ENV['SNAPSHOT'].to_i == 1
|
47
|
+
# version << "." << Time.now.utc.strftime("%Y%m%d%H%M%S")
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# Echoe.new('fuzzy_file_finder', version) do |p|
|
51
|
+
# p.author = "Jamis Buck"
|
52
|
+
# p.email = "jamis@jamisbuck.org"
|
53
|
+
# p.summary = "an implementation of TextMate's cmd-T search functionality"
|
54
|
+
#
|
55
|
+
# p.rdoc_pattern = /^(lib|README.rdoc)/
|
56
|
+
# end
|
data/lib/fuzzy_file_finder.rb
CHANGED
@@ -37,7 +37,7 @@ class FuzzyFileFinder
|
|
37
37
|
module Version
|
38
38
|
MAJOR = 1
|
39
39
|
MINOR = 0
|
40
|
-
TINY =
|
40
|
+
TINY = 1
|
41
41
|
STRING = [MAJOR, MINOR, TINY].join(".")
|
42
42
|
end
|
43
43
|
|
@@ -88,24 +88,29 @@ class FuzzyFileFinder
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
-
# The
|
92
|
-
attr_reader :
|
91
|
+
# The roots directory trees to search.
|
92
|
+
attr_reader :roots
|
93
93
|
|
94
94
|
# The maximum number of files and directories (combined).
|
95
95
|
attr_reader :ceiling
|
96
96
|
|
97
|
-
# The number of directories beneath +
|
97
|
+
# The number of directories beneath all +roots+
|
98
98
|
attr_reader :directory_count
|
99
99
|
|
100
|
-
# The number of files beneath +
|
100
|
+
# The number of files beneath all +roots+
|
101
101
|
attr_reader :file_count
|
102
102
|
|
103
103
|
# Initializes a new FuzzyFileFinder. This will scan the
|
104
104
|
# given +directory+, using +ceiling+ as the maximum number
|
105
105
|
# of entries to scan. If there are more than +ceiling+ entries
|
106
106
|
# a TooManyEntries exception will be raised.
|
107
|
-
def initialize(
|
108
|
-
|
107
|
+
def initialize(directories=['.'], ceiling=10_000)
|
108
|
+
directories = directories.any? ? directories : ['.']
|
109
|
+
|
110
|
+
# expand any paths with ~
|
111
|
+
root_dirnames = directories.map { |d| File.expand_path(d) }.select { |d| File.directory?(d) }
|
112
|
+
|
113
|
+
@roots = root_dirnames.map { |d| Directory.new(d) }
|
109
114
|
@ceiling = ceiling
|
110
115
|
rescan!
|
111
116
|
end
|
@@ -114,10 +119,10 @@ class FuzzyFileFinder
|
|
114
119
|
# you'll need to call this to force the finder to be aware of
|
115
120
|
# the changes.
|
116
121
|
def rescan!
|
117
|
-
|
122
|
+
roots.each { |r| r.children.clear }
|
118
123
|
@file_count = 0
|
119
124
|
@directory_count = 0
|
120
|
-
follow_tree(
|
125
|
+
roots.each { |r| follow_tree(r.name, r) }
|
121
126
|
end
|
122
127
|
|
123
128
|
# Takes the given +pattern+ (which must be a string) and searches
|
@@ -168,7 +173,9 @@ class FuzzyFileFinder
|
|
168
173
|
file_regex_raw = "^(.*?)" << make_pattern(file_name_part) << "(.*)$"
|
169
174
|
file_regex = Regexp.new(file_regex_raw, Regexp::IGNORECASE)
|
170
175
|
|
171
|
-
|
176
|
+
roots.each do |root|
|
177
|
+
do_search(path_regex, path_parts.length, file_regex, root, &block)
|
178
|
+
end
|
172
179
|
end
|
173
180
|
|
174
181
|
# Takes the given +pattern+ (which must be a string, formatted as
|
@@ -185,7 +192,7 @@ class FuzzyFileFinder
|
|
185
192
|
|
186
193
|
# Displays the finder object in a sane, non-explosive manner.
|
187
194
|
def inspect #:nodoc:
|
188
|
-
"#<%s:0x%x
|
195
|
+
"#<%s:0x%x roots=%s, files=%d, directories=%d>" % [self.class.name, object_id, roots.map { |r| r.name.inspect }.join(", "), file_count, directory_count]
|
189
196
|
end
|
190
197
|
|
191
198
|
private
|
@@ -285,10 +292,13 @@ class FuzzyFileFinder
|
|
285
292
|
path_match_score = 1
|
286
293
|
end
|
287
294
|
|
295
|
+
# determine whether +under+ is one of our root objects or not
|
296
|
+
is_root = roots.any? { |root| root == under }
|
297
|
+
|
288
298
|
# For each child of the directory, search under subdirectories, or
|
289
299
|
# match files.
|
290
300
|
under.children.each do |entry|
|
291
|
-
full =
|
301
|
+
full = is_root ? entry.name : File.join(under.name, entry.name)
|
292
302
|
if entry.directory?
|
293
303
|
do_search(path_regex, path_segments, file_regex, entry, &block)
|
294
304
|
elsif (path_regex.nil? || path_match) && file_match = entry.name.match(file_regex)
|
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.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jamis Buck
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-10-
|
12
|
+
date: 2008-10-11 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|