hike 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hike.rb +1 -1
  3. data/lib/hike/cached_trail.rb +21 -26
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 43eec4acb751a2c1c31260cfb077ce8dd15363d4
4
- data.tar.gz: ee1ef167fd5ada201bf64325b154ede3ca6312c3
3
+ metadata.gz: c46019e7383a433c30d2859e3e9da31a37623562
4
+ data.tar.gz: 25ec96e4f50c22d099f321c8ba11cf3a51c0d108
5
5
  SHA512:
6
- metadata.gz: fd38b8b3dae6aeb0d3c1a936251816d6d6f46ff1f1c635b67ddc06fe9a8505ce7adc8d47ed0ceca8a22fef3c4040a5f4af99bf01d6d6aac533cd6d92fb6a1fd7
7
- data.tar.gz: f55ece855a07db30efc55ce1f913c33933c6685da9032a5121b518fd97c59d7e340e403245199991290eeb2f1dcab099ce95e82d0017e124a1707eaa58e7ffea
6
+ metadata.gz: d3477f9cd81a43db8f296485ac46823c86749ca698745c68bcfd0bcca0061c8a9e654fed29138460c0f5ebf19198ba1da1c2773dcdf5ad141519ceca554a1a90
7
+ data.tar.gz: 0ba3c75b015858f23eee6960ab984a77e1226b0628bdcfc7f6ad5df89d2622a9f30ad27af1120063a947d42ab53f1ef8e12874ec6dffeb1d7372a23b5cc29dec
@@ -1,5 +1,5 @@
1
1
  module Hike
2
- VERSION = "2.1.0"
2
+ VERSION = "2.1.1"
3
3
 
4
4
  autoload :CachedTrail, "hike/cached_trail"
5
5
  autoload :Extensions, "hike/extensions"
@@ -1,5 +1,3 @@
1
- require 'pathname'
2
-
3
1
  module Hike
4
2
  # `CachedTrail` is an internal cached variant of `Trail`. It assumes the
5
3
  # file system does not change between `find` calls. All `stat` and
@@ -20,7 +18,7 @@ module Hike
20
18
  # `CachedTrail.new` is an internal method. Instead of constructing it
21
19
  # directly, create a `Trail` and call `Trail#CachedTrail`.
22
20
  def initialize(root, paths, extensions, aliases)
23
- @root = root
21
+ @root = root.to_s
24
22
 
25
23
  # Freeze is used here so an error is throw if a mutator method
26
24
  # is called on the array. Mutating `@paths`, `@extensions`, or
@@ -30,7 +28,6 @@ module Hike
30
28
  @aliases = aliases.inject({}) { |h, (k, a)|
31
29
  h[k] = a.dup.freeze; h
32
30
  }.freeze
33
- @pathnames = paths.map { |path| Pathname.new(path) }
34
31
 
35
32
  @stats = {}
36
33
  @entries = {}
@@ -38,9 +35,7 @@ module Hike
38
35
  end
39
36
 
40
37
  # `CachedTrail#root` returns root path as a `String`. This attribute is immutable.
41
- def root
42
- @root.to_s
43
- end
38
+ attr_reader :root
44
39
 
45
40
  # `CachedTrail#cached` returns `self` to be compatable with the `Trail` interface.
46
41
  def cached
@@ -66,10 +61,10 @@ module Hike
66
61
  return to_enum(__method__, *logical_paths) unless block_given?
67
62
 
68
63
  options = extract_options!(logical_paths)
69
- base_path = Pathname.new(options[:base_path] || @root)
64
+ base_path = (options[:base_path] || root).to_s
70
65
 
71
66
  logical_paths.each do |logical_path|
72
- logical_path = Pathname.new(logical_path.sub(/^\//, ''))
67
+ logical_path = logical_path.sub(/^\//, '')
73
68
 
74
69
  if relative?(logical_path)
75
70
  find_in_base_path(logical_path, base_path, &block)
@@ -104,23 +99,23 @@ module Hike
104
99
  arguments.last.is_a?(Hash) ? arguments.pop.dup : {}
105
100
  end
106
101
 
107
- def relative?(logical_path)
108
- logical_path.to_s =~ /^\.\.?\//
102
+ def relative?(path)
103
+ path =~ /^\.\.?\//
109
104
  end
110
105
 
111
106
  # Finds logical path across all `paths`
112
107
  def find_in_paths(logical_path, &block)
113
- dirname, basename = logical_path.split
114
- @pathnames.each do |base_path|
115
- match(base_path.join(dirname), basename, &block)
108
+ dirname, basename = File.split(logical_path)
109
+ @paths.each do |base_path|
110
+ match(File.expand_path(dirname, base_path), basename, &block)
116
111
  end
117
112
  end
118
113
 
119
114
  # Finds relative logical path, `../test/test_trail`. Requires a
120
115
  # `base_path` for reference.
121
116
  def find_in_base_path(logical_path, base_path, &block)
122
- candidate = base_path.join(logical_path)
123
- dirname, basename = candidate.split
117
+ candidate = File.expand_path(logical_path, base_path)
118
+ dirname, basename = File.split(candidate)
124
119
  match(dirname, basename, &block) if paths_contain?(dirname)
125
120
  end
126
121
 
@@ -134,21 +129,21 @@ module Hike
134
129
  matches = matches.select { |m| m =~ pattern }
135
130
 
136
131
  sort_matches(matches, basename).each do |path|
137
- pathname = dirname.join(path)
132
+ filename = File.join(dirname, path)
138
133
 
139
134
  # Potential `stat` syscall
140
- stat = stat(pathname)
135
+ stat = stat(filename)
141
136
 
142
137
  # Exclude directories
143
138
  if stat && stat.file?
144
- yield pathname.to_s
139
+ yield filename
145
140
  end
146
141
  end
147
142
  end
148
143
 
149
144
  # Returns true if `dirname` is a subdirectory of any of the `paths`
150
145
  def paths_contain?(dirname)
151
- paths.any? { |path| dirname.to_s[0, path.length] == path }
146
+ paths.any? { |path| dirname[0, path.length] == path }
152
147
  end
153
148
 
154
149
  # Cache results of `build_pattern_for`
@@ -160,16 +155,16 @@ module Hike
160
155
  #
161
156
  # pattern_for("index.html") #=> /^index(.html|.htm)(.builder|.erb)*$/
162
157
  def build_pattern_for(basename)
163
- extname = basename.extname
158
+ extname = File.extname(basename)
164
159
  aliases = find_aliases_for(extname)
165
160
 
166
161
  if aliases.any?
167
- basename = basename.basename(extname)
162
+ basename = File.basename(basename, extname)
168
163
  aliases = [extname] + aliases
169
164
  aliases_pattern = aliases.map { |e| Regexp.escape(e) }.join("|")
170
- basename_re = Regexp.escape(basename.to_s) + "(?:#{aliases_pattern})"
165
+ basename_re = Regexp.escape(basename) + "(?:#{aliases_pattern})"
171
166
  else
172
- basename_re = Regexp.escape(basename.to_s)
167
+ basename_re = Regexp.escape(basename)
173
168
  end
174
169
 
175
170
  extension_pattern = extensions.map { |e| Regexp.escape(e) }.join("|")
@@ -180,10 +175,10 @@ module Hike
180
175
  # priority. Extensions in the front of the `extensions` carry
181
176
  # more weight.
182
177
  def sort_matches(matches, basename)
183
- aliases = find_aliases_for(basename.extname)
178
+ aliases = find_aliases_for(File.extname(basename))
184
179
 
185
180
  matches.sort_by do |match|
186
- extnames = match.sub(basename.to_s, '').scan(/\.[^.]+/)
181
+ extnames = match.sub(basename, '').scan(/\.[^.]+/)
187
182
  extnames.inject(0) do |sum, ext|
188
183
  if i = extensions.index(ext)
189
184
  sum + i + 1
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.0
4
+ version: 2.1.1
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-17 00:00:00.000000000 Z
11
+ date: 2014-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake