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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10d721903c0073128042033159066e2ab6fa5270
4
- data.tar.gz: 8145fee7a51fdef0d35723a224c64f1a8edf5318
3
+ metadata.gz: a5e8217f19941dcb6f7060af726863789c844402
4
+ data.tar.gz: cc17e2e5cd8acfea2c85c608dde8ba8f8f4ecec4
5
5
  SHA512:
6
- metadata.gz: 82e16926972667047c562e3acd978570e803ff92d2b605902fe827c73ce632890484d3ec31adc1cd08af692ef7d0c3603d81894fba40055c8f566fb22ccade47
7
- data.tar.gz: 4acb4a1e48fba18914318dd53e31d4295b9f3c94a45ccacbf5127ba12704f3ee80a99589ddedd8037f9d4b2f434219da5a2d1de88fd8e4d8a553ed037f7c5d6f
6
+ metadata.gz: 255fd2e9685ba5b0df03b7606b7b8f5440b4de42b8c22eb030d3e4e513e68eae47d521bb372c3c2abb03aab2ff8c689d55731688736db8794dd4d76c28c22694
7
+ data.tar.gz: 30aaf4263534f08ce58b79c8ed2e0542051b2391341a3f892fb112531956bdf72e7a131639b8b4f40d02fb7b99e9db50c01d0873c40f17b5d37eea0ae646c4d3
@@ -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 to_pathname
55
- Pathname.new(
56
- self
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
  # --------------------------------------------------------------------------
@@ -5,5 +5,5 @@
5
5
  # ----------------------------------------------------------------------------
6
6
 
7
7
  class Pathutil
8
- VERSION = "0.0.2"
8
+ VERSION = "0.1.0"
9
9
  end
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.2
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-20 00:00:00.000000000 Z
11
+ date: 2016-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: forwardable-extended