hike 2.1.1 → 2.1.2
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.
- checksums.yaml +4 -4
- data/lib/hike.rb +1 -1
- data/lib/hike/cached_trail.rb +19 -32
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 797933ddf4e64187ab3a4e714147a41602fcd58e
|
4
|
+
data.tar.gz: dd13bfc57bb7239db82fb1ca3d543928ab3ba94f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3483da81e21e40f322abe6c39d20ddb52f52ba438095431624d9186726d3eb424713f2b118fb28f65d4dc25aef894f8a046f418d62292306ab807622ff670234
|
7
|
+
data.tar.gz: 7bb837bb3856a8d1898964c3e497835ef83ebd34b528fc5c65acc10e777562ec90e300748568302dd8c2534b06a7eeede9940c1bca91cc86df9bb65d98eb5cc1
|
data/lib/hike.rb
CHANGED
data/lib/hike/cached_trail.rb
CHANGED
@@ -25,13 +25,16 @@ module Hike
|
|
25
25
|
# `@aliases` would have unpredictable results.
|
26
26
|
@paths = paths.dup.freeze
|
27
27
|
@extensions = extensions.dup.freeze
|
28
|
-
@aliases = aliases.inject({}) { |h, (k, a)|
|
29
|
-
h[k] = a.dup.freeze; h
|
30
|
-
}.freeze
|
31
28
|
|
32
|
-
|
33
|
-
@
|
34
|
-
@
|
29
|
+
# Create a reverse mapping from extension to possible aliases.
|
30
|
+
@aliases = aliases.dup.freeze
|
31
|
+
@reverse_aliases = @aliases.inject({}) { |h, (k, a)|
|
32
|
+
(h[a] ||= []) << k; h
|
33
|
+
}
|
34
|
+
|
35
|
+
@stats = Hash.new { |h, k| h[k] = FileUtils.stat(k) }
|
36
|
+
@entries = Hash.new { |h, k| h[k] = FileUtils.entries(k) }
|
37
|
+
@patterns = Hash.new { |h, k| h[k] = pattern_for(k) }
|
35
38
|
end
|
36
39
|
|
37
40
|
# `CachedTrail#root` returns root path as a `String`. This attribute is immutable.
|
@@ -80,18 +83,13 @@ module Hike
|
|
80
83
|
# `~` swap files. Returns an empty `Array` if the directory does
|
81
84
|
# not exist.
|
82
85
|
def entries(path)
|
83
|
-
@entries[path
|
86
|
+
@entries[path]
|
84
87
|
end
|
85
88
|
|
86
89
|
# A cached version of `File.stat`. Returns nil if the file does
|
87
90
|
# not exist.
|
88
91
|
def stat(path)
|
89
|
-
|
90
|
-
if @stats.key?(key)
|
91
|
-
@stats[key]
|
92
|
-
else
|
93
|
-
@stats[key] = super
|
94
|
-
end
|
92
|
+
@stats[path]
|
95
93
|
end
|
96
94
|
|
97
95
|
protected
|
@@ -123,16 +121,16 @@ module Hike
|
|
123
121
|
# any syscalls if necessary.
|
124
122
|
def match(dirname, basename)
|
125
123
|
# Potential `entries` syscall
|
126
|
-
matches = entries
|
124
|
+
matches = @entries[dirname]
|
127
125
|
|
128
|
-
pattern =
|
126
|
+
pattern = @patterns[basename]
|
129
127
|
matches = matches.select { |m| m =~ pattern }
|
130
128
|
|
131
129
|
sort_matches(matches, basename).each do |path|
|
132
130
|
filename = File.join(dirname, path)
|
133
131
|
|
134
132
|
# Potential `stat` syscall
|
135
|
-
stat =
|
133
|
+
stat = @stats[filename]
|
136
134
|
|
137
135
|
# Exclude directories
|
138
136
|
if stat && stat.file?
|
@@ -146,19 +144,14 @@ module Hike
|
|
146
144
|
paths.any? { |path| dirname[0, path.length] == path }
|
147
145
|
end
|
148
146
|
|
149
|
-
# Cache results of `build_pattern_for`
|
150
|
-
def pattern_for(basename)
|
151
|
-
@patterns[basename] ||= build_pattern_for(basename)
|
152
|
-
end
|
153
|
-
|
154
147
|
# Returns a `Regexp` that matches the allowed extensions.
|
155
148
|
#
|
156
149
|
# pattern_for("index.html") #=> /^index(.html|.htm)(.builder|.erb)*$/
|
157
|
-
def
|
150
|
+
def pattern_for(basename)
|
158
151
|
extname = File.extname(basename)
|
159
|
-
aliases =
|
152
|
+
aliases = @reverse_aliases[extname]
|
160
153
|
|
161
|
-
if aliases
|
154
|
+
if aliases
|
162
155
|
basename = File.basename(basename, extname)
|
163
156
|
aliases = [extname] + aliases
|
164
157
|
aliases_pattern = aliases.map { |e| Regexp.escape(e) }.join("|")
|
@@ -175,7 +168,8 @@ module Hike
|
|
175
168
|
# priority. Extensions in the front of the `extensions` carry
|
176
169
|
# more weight.
|
177
170
|
def sort_matches(matches, basename)
|
178
|
-
|
171
|
+
extname = File.extname(basename)
|
172
|
+
aliases = @reverse_aliases[extname] || []
|
179
173
|
|
180
174
|
matches.sort_by do |match|
|
181
175
|
extnames = match.sub(basename, '').scan(/\.[^.]+/)
|
@@ -190,12 +184,5 @@ module Hike
|
|
190
184
|
end
|
191
185
|
end
|
192
186
|
end
|
193
|
-
|
194
|
-
def find_aliases_for(extension)
|
195
|
-
@aliases.inject([]) do |aliases, (key, value)|
|
196
|
-
aliases.push(key) if value == extension
|
197
|
-
aliases
|
198
|
-
end
|
199
|
-
end
|
200
187
|
end
|
201
188
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hike
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Stephenson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|