parent_paths 0.0.1
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 +7 -0
- data/LICENSE +20 -0
- data/README.md +37 -0
- data/lib/parent_paths/version.rb +3 -0
- data/lib/parent_paths.rb +46 -0
- data/parent_paths.gemspec +19 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1a4a0e640330c967e7be13321bc60e72d75b7747
|
4
|
+
data.tar.gz: 89a646b1e73688a5e3498f8a0fb14dd43cbaa8e6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 95498e8bc02b836ee619c1234209eefac3fd999afbc75ec4a1248b59a92b9a4f57dd27de8e0676b37b3d22c315c2949e183f75ee4af52cfbf25c03e82bafee70
|
7
|
+
data.tar.gz: 4d9555c784b51b788978ed2f38fbd3031fe9fa66f1b958e47a8fbe1d50d40fc1612d4acc9d3595d98e9de6b6fbc0420369b98eca4b293fd6dcf177bee0100b86
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Jeff Lee
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# parent_paths
|
2
|
+
|
3
|
+
Handy methods for scanning parent paths.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Include `parent_paths` in your Gemfile, or call `gem install parent_paths`.
|
8
|
+
|
9
|
+
## `ParentPaths` module
|
10
|
+
|
11
|
+
### scan(start = nil, &criteria)
|
12
|
+
|
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
|
+
|
15
|
+
If a starting path is not provided, it is assumed to be the path of the file that calls this method.
|
16
|
+
|
17
|
+
```
|
18
|
+
# Find the first ancestor directory of the current file to contain more than 5
|
19
|
+
# files
|
20
|
+
ParentPaths.scan do |path|
|
21
|
+
Dir.glob(path + '*').size > 5
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
### scan_for_owner(filename, start = nil)
|
26
|
+
|
27
|
+
From the given starting path, scan upward through the file hierachy until a particular filename is discovered.
|
28
|
+
|
29
|
+
If a starting path is not provided, it is assumed to be the path of the file that calls this method.
|
30
|
+
|
31
|
+
```
|
32
|
+
# Find the first ancestor directory of the current file that contains a
|
33
|
+
# particular filename.
|
34
|
+
ParentPaths.scan_for_owner('Gemfile')
|
35
|
+
```
|
36
|
+
|
37
|
+
|
data/lib/parent_paths.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module ParentPaths
|
4
|
+
|
5
|
+
# From the given starting path, scan upward through the file hierachy until
|
6
|
+
# a particular criteria is met. The criteria is determined by a block that
|
7
|
+
# receives the path of the next directory in the hierarchy.
|
8
|
+
#
|
9
|
+
# If a starting path is not provided, it is assumed to be the path of the
|
10
|
+
# file that calls this method.
|
11
|
+
def self.scan(start = nil, &criteria)
|
12
|
+
start ||= caller_path
|
13
|
+
start = Pathname.new(start)
|
14
|
+
if criteria.call(start)
|
15
|
+
return start
|
16
|
+
else
|
17
|
+
parent = start.parent
|
18
|
+
if start == parent
|
19
|
+
nil
|
20
|
+
else
|
21
|
+
scan parent, &criteria
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# From the given starting path, scan upward through the file hierachy until
|
27
|
+
# a particular filename is discovered.
|
28
|
+
#
|
29
|
+
# If a starting path is not provided, it is assumed to be the path of the
|
30
|
+
# file that calls this method.
|
31
|
+
def self.scan_for_owner(filename, start = nil)
|
32
|
+
start ||= caller_path
|
33
|
+
scan(start) { |pathname| File.exist?(pathname + filename) }
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
# Returns the path of the file that calls the method that calls caller_path.
|
39
|
+
# For example if, foo.rb#foo calls caller_path, calling foo.rb#foo will return
|
40
|
+
# the current file.
|
41
|
+
def self.caller_path
|
42
|
+
matches = caller(2).first.match(/(.*):\d+:in `/)
|
43
|
+
Pathname.new(File.expand_path(matches[1]))
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$:.unshift File.expand_path("../lib", __FILE__)
|
3
|
+
require 'parent_paths/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'parent_paths'
|
7
|
+
s.licenses = ['MIT']
|
8
|
+
s.summary = "Handy methods for scanning parent paths"
|
9
|
+
s.version = ParentPaths::VERSION
|
10
|
+
s.homepage = 'https://github.com/jeffomatic/parent_paths'
|
11
|
+
|
12
|
+
s.authors = ["Jeff Lee"]
|
13
|
+
s.email = 'jeffomatic@gmail.com'
|
14
|
+
|
15
|
+
s.files = %w( README.md LICENSE parent_paths.gemspec )
|
16
|
+
s.files += Dir.glob('lib/**/*')
|
17
|
+
|
18
|
+
s.add_development_dependency('rspec', '~>2.14.1')
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: parent_paths
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeff Lee
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
type: :development
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 2.14.1
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.14.1
|
27
|
+
description:
|
28
|
+
email: jeffomatic@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- README.md
|
34
|
+
- LICENSE
|
35
|
+
- parent_paths.gemspec
|
36
|
+
- lib/parent_paths/version.rb
|
37
|
+
- lib/parent_paths.rb
|
38
|
+
homepage: https://github.com/jeffomatic/parent_paths
|
39
|
+
licenses:
|
40
|
+
- MIT
|
41
|
+
metadata: {}
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 2.1.11
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: Handy methods for scanning parent paths
|
62
|
+
test_files: []
|