hike 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 43eec4acb751a2c1c31260cfb077ce8dd15363d4
4
+ data.tar.gz: ee1ef167fd5ada201bf64325b154ede3ca6312c3
5
+ SHA512:
6
+ metadata.gz: fd38b8b3dae6aeb0d3c1a936251816d6d6f46ff1f1c635b67ddc06fe9a8505ce7adc8d47ed0ceca8a22fef3c4040a5f4af99bf01d6d6aac533cd6d92fb6a1fd7
7
+ data.tar.gz: f55ece855a07db30efc55ce1f913c33933c6685da9032a5121b518fd97c59d7e340e403245199991290eeb2f1dcab099ce95e82d0017e124a1707eaa58e7ffea
@@ -1,8 +1,9 @@
1
1
  module Hike
2
- VERSION = "1.2.0"
2
+ VERSION = "2.1.0"
3
3
 
4
4
  autoload :CachedTrail, "hike/cached_trail"
5
5
  autoload :Extensions, "hike/extensions"
6
+ autoload :FileUtils, "hike/fileutils"
6
7
  autoload :NormalizedArray, "hike/normalized_array"
7
8
  autoload :Paths, "hike/paths"
8
9
  autoload :Trail, "hike/trail"
@@ -5,6 +5,8 @@ module Hike
5
5
  # file system does not change between `find` calls. All `stat` and
6
6
  # `entries` calls are cached for the lifetime of the `CachedTrail` object.
7
7
  class CachedTrail
8
+ include FileUtils
9
+
8
10
  # `CachedTrail#paths` is an immutable `Paths` collection.
9
11
  attr_reader :paths
10
12
 
@@ -83,14 +85,7 @@ module Hike
83
85
  # `~` swap files. Returns an empty `Array` if the directory does
84
86
  # not exist.
85
87
  def entries(path)
86
- @entries[path.to_s] ||= begin
87
- pathname = Pathname.new(path)
88
- if pathname.directory?
89
- pathname.entries.reject { |entry| entry.to_s =~ /^\.|~$|^\#.*\#$/ }.sort
90
- else
91
- []
92
- end
93
- end
88
+ @entries[path.to_s] ||= super
94
89
  end
95
90
 
96
91
  # A cached version of `File.stat`. Returns nil if the file does
@@ -99,10 +94,8 @@ module Hike
99
94
  key = path.to_s
100
95
  if @stats.key?(key)
101
96
  @stats[key]
102
- elsif File.exist?(path)
103
- @stats[key] = File.stat(path)
104
97
  else
105
- @stats[key] = nil
98
+ @stats[key] = super
106
99
  end
107
100
  end
108
101
 
@@ -138,7 +131,7 @@ module Hike
138
131
  matches = entries(dirname)
139
132
 
140
133
  pattern = pattern_for(basename)
141
- matches = matches.select { |m| m.to_s =~ pattern }
134
+ matches = matches.select { |m| m =~ pattern }
142
135
 
143
136
  sort_matches(matches, basename).each do |path|
144
137
  pathname = dirname.join(path)
@@ -190,7 +183,7 @@ module Hike
190
183
  aliases = find_aliases_for(basename.extname)
191
184
 
192
185
  matches.sort_by do |match|
193
- extnames = match.sub(basename.to_s, '').to_s.scan(/\.[^.]+/)
186
+ extnames = match.sub(basename.to_s, '').scan(/\.[^.]+/)
194
187
  extnames.inject(0) do |sum, ext|
195
188
  if i = extensions.index(ext)
196
189
  sum + i + 1
@@ -0,0 +1,24 @@
1
+ module Hike
2
+ module FileUtils
3
+ extend self
4
+
5
+ # Like `File.stat`. Returns nil if the file does not exist.
6
+ def stat(path)
7
+ if File.exist?(path)
8
+ File.stat(path.to_s)
9
+ else
10
+ nil
11
+ end
12
+ end
13
+
14
+ # A version of `Dir.entries` that filters out `.` files and `~` swap files.
15
+ # Returns an empty `Array` if the directory does not exist.
16
+ def entries(path)
17
+ if File.directory?(path)
18
+ Dir.entries(path).reject { |entry| entry =~ /^\.|~$|^\#.*\#$/ }.sort
19
+ else
20
+ []
21
+ end
22
+ end
23
+ end
24
+ end
@@ -6,6 +6,8 @@ require 'hike/paths'
6
6
  module Hike
7
7
  # `Trail` is the public container class for holding paths and extensions.
8
8
  class Trail
9
+ include FileUtils
10
+
9
11
  # `Trail#paths` is a mutable `Paths` collection.
10
12
  #
11
13
  # trail = Hike::Trail.new
@@ -160,29 +162,6 @@ module Hike
160
162
  # Deprecated alias for `cached`.
161
163
  alias_method :index, :cached
162
164
 
163
- # `Trail#entries` is equivalent to `Dir#entries`. It is not
164
- # recommend to use this method for general purposes. It exists for
165
- # parity with `CachedTrail#entries`.
166
- def entries(path)
167
- pathname = Pathname.new(path)
168
- if pathname.directory?
169
- pathname.entries.reject { |entry| entry.to_s =~ /^\.|~$|^\#.*\#$/ }.sort
170
- else
171
- []
172
- end
173
- end
174
-
175
- # `Trail#stat` is equivalent to `File#stat`. It is not
176
- # recommend to use this method for general purposes. It exists for
177
- # parity with `CachedTrail#stat`.
178
- def stat(path)
179
- if File.exist?(path)
180
- File.stat(path.to_s)
181
- else
182
- nil
183
- end
184
- end
185
-
186
165
  private
187
166
  def normalize_extension(extension)
188
167
  if extension[/^\./]
metadata CHANGED
@@ -1,30 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hike
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
5
- prerelease:
4
+ version: 2.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Sam Stephenson
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-04-03 00:00:00.000000000 Z
11
+ date: 2014-04-17 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  description: A Ruby library for finding files in a set of paths.
@@ -38,6 +35,7 @@ files:
38
35
  - LICENSE
39
36
  - lib/hike/cached_trail.rb
40
37
  - lib/hike/extensions.rb
38
+ - lib/hike/fileutils.rb
41
39
  - lib/hike/normalized_array.rb
42
40
  - lib/hike/paths.rb
43
41
  - lib/hike/trail.rb
@@ -45,26 +43,26 @@ files:
45
43
  homepage: http://github.com/sstephenson/hike
46
44
  licenses:
47
45
  - MIT
46
+ metadata: {}
48
47
  post_install_message:
49
48
  rdoc_options: []
50
49
  require_paths:
51
50
  - lib
52
51
  required_ruby_version: !ruby/object:Gem::Requirement
53
- none: false
54
52
  requirements:
55
- - - ! '>='
53
+ - - '>='
56
54
  - !ruby/object:Gem::Version
57
55
  version: 1.9.3
58
56
  required_rubygems_version: !ruby/object:Gem::Requirement
59
- none: false
60
57
  requirements:
61
- - - ! '>='
58
+ - - '>='
62
59
  - !ruby/object:Gem::Version
63
60
  version: '0'
64
61
  requirements: []
65
62
  rubyforge_project:
66
- rubygems_version: 1.8.23
63
+ rubygems_version: 2.0.3
67
64
  signing_key:
68
- specification_version: 3
65
+ specification_version: 4
69
66
  summary: Find files in a set of paths
70
67
  test_files: []
68
+ has_rdoc: