walk_up 0.0.10 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/walk_up.rb +21 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1682cc294cec6c48260095c64f8cb8ce89504f568a92113f207ea449a0b4af1a
|
4
|
+
data.tar.gz: 73793b437dd3b3b076687897c040afa475a58bdbeeed5e9aa5e666fe752a96ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c93ad6e45760152065346c28e2a8a8fe0495b1986a4590c65d72674a8b00a77f25658872575adf9a737259052d52a0fb0e956c683b9c8f4637e34e0a98ddbd9
|
7
|
+
data.tar.gz: 2e43b283a809c1ea3c882460f89ba0ece2c3ef450a2a2600a591a6d45c7c97a915855bc2689b32f8720fdc1658c7552eb45839ff147f14c5e4e1f336c510dec3
|
data/lib/walk_up.rb
CHANGED
@@ -1,3 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require "pathname"
|
2
3
|
|
3
|
-
|
4
|
+
def walk_up(file_to_find, start_path=nil)
|
5
|
+
here = start_path || Dir.pwd
|
6
|
+
# if absolute
|
7
|
+
if not Pathname.new(here).absolute?
|
8
|
+
here = File.join(Dir.pwd, here)
|
9
|
+
end
|
10
|
+
loop do
|
11
|
+
check_path = File.join(here, file_to_find)
|
12
|
+
if File.exist?(check_path)
|
13
|
+
return here
|
14
|
+
end
|
15
|
+
# reached the top
|
16
|
+
if here == File.dirname(here)
|
17
|
+
return nil
|
18
|
+
# else go up one and try again
|
19
|
+
else
|
20
|
+
here = File.dirname(here)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|