parent_paths 0.0.2 → 0.0.3
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/README.md +4 -4
- data/lib/parent_paths/version.rb +1 -1
- data/lib/parent_paths.rb +4 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81f9210b7c28d25e97600ff562291dd4f1b31394
|
4
|
+
data.tar.gz: 4baab1d17ef63cabffba23deda7da2a370e486fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6ad4125294f2705ed8a94f426b159723e2b7a94c6f393525f0763e171801c48b7236848a21710bbacaead28398177832ba4a59957233e880cd7abe9d8dd5f7a
|
7
|
+
data.tar.gz: 476c5509ddd5ca99edd30cc6378793399e70eecbb68af52d7a4ecfcd749e992adf5353202f514da0a1eb658de624a3f9941a8055490acce99f4b0efd67acbd1e
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@ Include `parent_paths` in your Gemfile, or call `gem install parent_paths`.
|
|
8
8
|
|
9
9
|
## `ParentPaths` module
|
10
10
|
|
11
|
-
###
|
11
|
+
### find(start = nil, &criteria)
|
12
12
|
|
13
13
|
From the given starting path, scan upward through the file hierachy until a particular criteria is met. The criteria is determined by a block that receives the path of the next directory in the hierarchy.
|
14
14
|
|
@@ -17,12 +17,12 @@ If a starting path is not provided, it is assumed to be the path of the file tha
|
|
17
17
|
```
|
18
18
|
# Find the first ancestor directory of the current file to contain more than 5
|
19
19
|
# files
|
20
|
-
ParentPaths.
|
20
|
+
ParentPaths.find do |path|
|
21
21
|
Dir.glob(path + '*').size > 5
|
22
22
|
end
|
23
23
|
```
|
24
24
|
|
25
|
-
###
|
25
|
+
### find_owner(filename, start = nil)
|
26
26
|
|
27
27
|
From the given starting path, scan upward through the file hierachy until a particular filename is discovered.
|
28
28
|
|
@@ -31,7 +31,7 @@ If a starting path is not provided, it is assumed to be the path of the file tha
|
|
31
31
|
```
|
32
32
|
# Find the first ancestor directory of the current file that contains a
|
33
33
|
# particular filename.
|
34
|
-
ParentPaths.
|
34
|
+
ParentPaths.find_owner('Gemfile')
|
35
35
|
```
|
36
36
|
|
37
37
|
|
data/lib/parent_paths/version.rb
CHANGED
data/lib/parent_paths.rb
CHANGED
@@ -8,7 +8,7 @@ module ParentPaths
|
|
8
8
|
#
|
9
9
|
# If a starting path is not provided, it is assumed to be the path of the
|
10
10
|
# file that calls this method.
|
11
|
-
def self.
|
11
|
+
def self.find(start = nil, &criteria)
|
12
12
|
start ||= caller_path
|
13
13
|
if criteria.call(start)
|
14
14
|
return start
|
@@ -17,7 +17,7 @@ module ParentPaths
|
|
17
17
|
if start == parent
|
18
18
|
nil
|
19
19
|
else
|
20
|
-
|
20
|
+
find parent, &criteria
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -27,9 +27,9 @@ module ParentPaths
|
|
27
27
|
#
|
28
28
|
# If a starting path is not provided, it is assumed to be the path of the
|
29
29
|
# file that calls this method.
|
30
|
-
def self.
|
30
|
+
def self.find_owner(filename, start = nil)
|
31
31
|
start ||= caller_path
|
32
|
-
|
32
|
+
find(start) { |path| File.exist?(File.join(path, filename)) }
|
33
33
|
end
|
34
34
|
|
35
35
|
private
|