hike 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/LICENSE +20 -0
  2. data/README.md +52 -0
  3. data/lib/hike.rb +1 -1
  4. data/lib/hike/index.rb +24 -22
  5. data/lib/hike/trail.rb +14 -0
  6. metadata +6 -4
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Sam Stephenson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,52 @@
1
+ Hike
2
+ ====
3
+
4
+ Hike is a Ruby library for finding files in a set of paths. Use it to
5
+ implement search paths, load paths, and the like.
6
+
7
+ # Examples
8
+
9
+ Find Ruby files in this project:
10
+
11
+ trail = Hike::Trail.new "/Users/sam/Projects/hike"
12
+ trail.extensions.push ".rb"
13
+ trail.paths.push "lib", "test"
14
+
15
+ trail.find "hike/trail"
16
+ # => "/Users/sam/Projects/hike/lib/hike/trail.rb"
17
+
18
+ trail.find "test_trail"
19
+ # => "/Users/sam/Projects/hike/test/test_trail.rb"
20
+
21
+ Explore your Ruby load path:
22
+
23
+ trail = Hike::Trail.new "/"
24
+ trail.extensions.push ".rb", ".bundle"
25
+ trail.paths.replace $:
26
+
27
+ trail.find "net/http"
28
+ # => "/Users/sam/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/net/http.rb"
29
+
30
+ trail.find "strscan"
31
+ # => "/Users/sam/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/1.8/i686-darwin10.4.0/strscan.bundle"
32
+
33
+ Explore your shell path:
34
+
35
+ trail = Hike::Trail.new "/"
36
+ trail.paths.replace ENV["PATH"].split(":")
37
+
38
+ trail.find "ls"
39
+ # => "/bin/ls"
40
+
41
+ trail.find "gem"
42
+ # => "/Users/sam/.rvm/rubies/ree-1.8.7-2010.02/bin/gem"
43
+
44
+ # Installation
45
+
46
+ $ gem install hike
47
+
48
+ # License
49
+
50
+ Copyright (c) 2010 Sam Stephenson.
51
+
52
+ Released under the MIT license. See `LICENSE` for details.
@@ -1,5 +1,5 @@
1
1
  module Hike
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
 
4
4
  autoload :Extensions, "hike/extensions"
5
5
  autoload :Index, "hike/index"
@@ -65,6 +65,30 @@ module Hike
65
65
  end
66
66
  end
67
67
 
68
+ # A cached version of `Dir.entries` that filters out `.` and
69
+ # `..`. Returns an empty `Array` if the directory does not exist.
70
+ def entries(path)
71
+ key = path.to_s
72
+ @entries[key] ||= Pathname.new(path).entries.reject { |entry| entry.to_s =~ /^\.\.?$/ }
73
+ rescue Errno::ENOENT
74
+ @entries[key] = []
75
+ end
76
+
77
+ # A cached version of `File.stat`. Returns nil if the file does
78
+ # not exist.
79
+ def stat(path)
80
+ key = path.to_s
81
+ if @stats.key?(key)
82
+ @stats[key]
83
+ else
84
+ begin
85
+ @stats[key] = File.stat(path)
86
+ rescue Errno::ENOENT
87
+ @stats[key] = nil
88
+ end
89
+ end
90
+ end
91
+
68
92
  protected
69
93
  def extract_options!(arguments)
70
94
  arguments.last.is_a?(Hash) ? arguments.pop.dup : {}
@@ -112,28 +136,6 @@ module Hike
112
136
  end
113
137
  end
114
138
 
115
- # A cached version of `File.stat`. Returns nil if the file does
116
- # not exist.
117
- def stat(pathname)
118
- if @stats.key?(pathname)
119
- @stats[pathname]
120
- else
121
- begin
122
- @stats[pathname] = pathname.stat
123
- rescue Errno::ENOENT
124
- @stats[pathname] = nil
125
- end
126
- end
127
- end
128
-
129
- # A cached version of `Dir.entries` that filters out `.` and
130
- # `..`. Returns an empty `Array` if the directory does not exist.
131
- def entries(pathname)
132
- @entries[pathname] ||= pathname.entries.reject { |entry| entry.to_s =~ /^\.\.?$/ }
133
- rescue Errno::ENOENT
134
- @entries[pathname] = []
135
- end
136
-
137
139
  # Returns true if `dirname` is a subdirectory of any of the `paths`
138
140
  def paths_contain?(dirname)
139
141
  paths.any? { |path| dirname.to_s[0, path.length] == path }
@@ -93,5 +93,19 @@ module Hike
93
93
  def index
94
94
  Index.new(root, paths, extensions)
95
95
  end
96
+
97
+ # `Trail#entries` is equivalent to `Dir#entries`. It is not
98
+ # recommend to use this method for general purposes. It exists for
99
+ # parity with `Index#entries`.
100
+ def entries(*args)
101
+ index.entries(*args)
102
+ end
103
+
104
+ # `Trail#stat` is equivalent to `File#stat`. It is not
105
+ # recommend to use this method for general purposes. It exists for
106
+ # parity with `Index#stat`.
107
+ def stat(*args)
108
+ index.stat(*args)
109
+ end
96
110
  end
97
111
  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: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 1.0.0
10
+ version: 1.1.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: 2011-04-28 00:00:00 -05:00
18
+ date: 2011-06-14 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -29,6 +29,8 @@ extensions: []
29
29
  extra_rdoc_files: []
30
30
 
31
31
  files:
32
+ - README.md
33
+ - LICENSE
32
34
  - lib/hike/extensions.rb
33
35
  - lib/hike/index.rb
34
36
  - lib/hike/normalized_array.rb