hike 0.1.5 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/hike.rb +1 -1
- data/lib/hike/trail.rb +30 -6
- metadata +5 -5
data/lib/hike.rb
CHANGED
data/lib/hike/trail.rb
CHANGED
@@ -10,12 +10,21 @@ module Hike
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def find(*logical_paths)
|
13
|
+
options = logical_paths.last.is_a?(Hash) ? logical_paths.pop : {}
|
14
|
+
if relative_to = options[:relative_to]
|
15
|
+
base_path = File.dirname(relative_to)
|
16
|
+
end
|
17
|
+
|
13
18
|
index.expire_cache
|
14
19
|
|
15
20
|
logical_paths.each do |logical_path|
|
16
|
-
if
|
17
|
-
|
21
|
+
if relative_to
|
22
|
+
result = find_path_relative(logical_path, base_path)
|
23
|
+
else
|
24
|
+
result = find_path(logical_path)
|
18
25
|
end
|
26
|
+
|
27
|
+
return File.expand_path(result) if result
|
19
28
|
end
|
20
29
|
nil
|
21
30
|
end
|
@@ -27,14 +36,29 @@ module Hike
|
|
27
36
|
dirname, basename = File.split(logical_path)
|
28
37
|
pattern = filename_pattern_for(basename)
|
29
38
|
|
30
|
-
paths.each do |
|
31
|
-
path = File.join(
|
32
|
-
|
33
|
-
|
39
|
+
paths.each do |base_path|
|
40
|
+
if path = find_in_base(File.join(base_path, dirname), basename, pattern)
|
41
|
+
return path
|
42
|
+
end
|
34
43
|
end
|
35
44
|
nil
|
36
45
|
end
|
37
46
|
|
47
|
+
def find_path_relative(logical_path, base_path)
|
48
|
+
dirname, basename = File.split(File.join(base_path, logical_path))
|
49
|
+
dirname = File.expand_path(dirname)
|
50
|
+
pattern = filename_pattern_for(basename)
|
51
|
+
|
52
|
+
if paths.any? { |path| dirname[0, path.length] == path }
|
53
|
+
find_in_base(File.expand_path(dirname), basename, pattern)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def find_in_base(base_path, base_name, pattern)
|
58
|
+
matches = match_files_in(base_path, pattern)
|
59
|
+
File.join(base_path, match_from(matches, base_name)) unless matches.empty?
|
60
|
+
end
|
61
|
+
|
38
62
|
def match_files_in(dirname, pattern)
|
39
63
|
index.files(dirname).grep(pattern)
|
40
64
|
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: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
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-11-
|
18
|
+
date: 2010-11-23 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|