hike 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/hike.rb +1 -1
- data/lib/hike/trail.rb +40 -20
- metadata +4 -4
data/lib/hike.rb
CHANGED
data/lib/hike/trail.rb
CHANGED
@@ -10,39 +10,59 @@ module Hike
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def find(*logical_paths)
|
13
|
-
|
14
|
-
candidates = candidates_for_paths(logical_paths)
|
13
|
+
index.expire_mtimes
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
return filename if exists?(filename)
|
15
|
+
logical_paths.each do |logical_path|
|
16
|
+
if result = find_path(logical_path)
|
17
|
+
return result
|
20
18
|
end
|
21
19
|
end
|
22
|
-
|
23
20
|
nil
|
24
21
|
end
|
25
22
|
|
26
23
|
protected
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
attr_reader :index
|
25
|
+
|
26
|
+
def find_path(logical_path)
|
27
|
+
dirname, basename = File.split(logical_path)
|
28
|
+
pattern = filename_pattern_for(basename)
|
29
|
+
|
30
|
+
paths.each do |root|
|
31
|
+
path = File.join(root, dirname)
|
32
|
+
matches = match_files_in(path, pattern)
|
33
|
+
return File.join(path, match_from(matches, basename)) unless matches.empty?
|
34
|
+
end
|
35
|
+
nil
|
31
36
|
end
|
32
37
|
|
33
|
-
def
|
34
|
-
|
35
|
-
candidates.unshift(logical_path) if has_extension?(logical_path)
|
36
|
-
candidates
|
38
|
+
def match_files_in(dirname, pattern)
|
39
|
+
index.files(dirname).grep(pattern)
|
37
40
|
end
|
38
41
|
|
39
|
-
def
|
40
|
-
extensions.
|
42
|
+
def filename_pattern_for(basename)
|
43
|
+
extension_pattern = extensions.map { |e| Regexp.escape(e) }.join("|")
|
44
|
+
extension_pattern += "|" if has_registered_extension?(basename)
|
45
|
+
/^#{Regexp.escape(basename)}(?:#{extension_pattern})$/
|
46
|
+
end
|
47
|
+
|
48
|
+
def match_from(matches, basename)
|
49
|
+
if matches.length == 1
|
50
|
+
matches.first
|
51
|
+
elsif matches.length > 1
|
52
|
+
ordered_match_from(matches, basename)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def ordered_match_from(matches, basename)
|
57
|
+
extensions.each do |extension|
|
58
|
+
candidate = basename + extension
|
59
|
+
return candidate if matches.include?(candidate)
|
60
|
+
end
|
61
|
+
basename
|
41
62
|
end
|
42
63
|
|
43
|
-
def
|
44
|
-
|
45
|
-
@index.files(dirname).include?(basename)
|
64
|
+
def has_registered_extension?(logical_path)
|
65
|
+
extensions.include?(File.extname(logical_path))
|
46
66
|
end
|
47
67
|
end
|
48
68
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hike
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sam Stephenson
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-19 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|