pathutil 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pathutil.rb +37 -4
- data/lib/pathutil/version.rb +1 -1
- 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: a5e8217f19941dcb6f7060af726863789c844402
|
4
|
+
data.tar.gz: cc17e2e5cd8acfea2c85c608dde8ba8f8f4ecec4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 255fd2e9685ba5b0df03b7606b7b8f5440b4de42b8c22eb030d3e4e513e68eae47d521bb372c3c2abb03aab2ff8c689d55731688736db8794dd4d76c28c22694
|
7
|
+
data.tar.gz: 30aaf4263534f08ce58b79c8ed2e0542051b2391341a3f892fb112531956bdf72e7a131639b8b4f40d02fb7b99e9db50c01d0873c40f17b5d37eea0ae646c4d3
|
data/lib/pathutil.rb
CHANGED
@@ -49,12 +49,45 @@ class Pathutil
|
|
49
49
|
@path = path.respond_to?(:to_path) ? path.to_path : path.to_s
|
50
50
|
end
|
51
51
|
|
52
|
+
# --------------------------------------------------------------------------
|
53
|
+
# Search backwards for a file (like Rakefile, _config.yml, opts.yml).
|
54
|
+
# @note It will return all results that it finds across all ascending paths.
|
55
|
+
# @param backwards how far do you wish to search backwards in that path?
|
56
|
+
# @param file the file you are searching for.
|
57
|
+
#
|
58
|
+
# @example
|
59
|
+
# Pathutil.new("~/").expand_path.search_backwards(".bashrc") => [
|
60
|
+
# #<Pathutil:/home/user/.bashrc>
|
61
|
+
# ]
|
52
62
|
# --------------------------------------------------------------------------
|
53
63
|
|
54
|
-
def
|
55
|
-
|
56
|
-
|
57
|
-
)
|
64
|
+
def search_backwards(file, backwards: Float::INFINITY)
|
65
|
+
ary = []
|
66
|
+
|
67
|
+
ascend.with_index(1).each do |path, index|
|
68
|
+
if index > backwards
|
69
|
+
break
|
70
|
+
|
71
|
+
else
|
72
|
+
Dir.chdir path do
|
73
|
+
if block_given?
|
74
|
+
file = self.class.new(file)
|
75
|
+
if yield(file)
|
76
|
+
ary.push(
|
77
|
+
self
|
78
|
+
)
|
79
|
+
end
|
80
|
+
|
81
|
+
elsif File.exist?(file)
|
82
|
+
ary.push(self.class.new(
|
83
|
+
path.join(file)
|
84
|
+
))
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
ary
|
58
91
|
end
|
59
92
|
|
60
93
|
# --------------------------------------------------------------------------
|
data/lib/pathutil/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pathutil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordon Bedwell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: forwardable-extended
|