get_root 0.1.0
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 +25 -0
- data/README.md +65 -0
- data/lib/get_root.rb +30 -0
- data/lib/get_root/version.rb +5 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a35e413a287125eaa15eaf2bd9f4e3e815b5c77335d8367c2980426e9021c4e1
|
4
|
+
data.tar.gz: 5070fd9c13fda1a5c7e785b82a361c888d167a4bcf9ea00fbd2496d2cb2101d9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4f113f67cbd872cdc7ff7b5e337f47e58ea2021e33db30b0c5e2728eb560af0aedfbb0f671c4ce9e5adc0e179dbd1f6149faf0a8b448e65da7ef365cdcb6ea32
|
7
|
+
data.tar.gz: 1413b4db180e95bfe8ea0fac419b770ef34be71e243a4ce34f25df70bc71f06e19f2939a9625357c554d178207ae58048728928ee8d67dbe7856df04498ef83b
|
data/LICENSE
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
MIT License
|
2
|
+
===========
|
3
|
+
|
4
|
+
Copyright (©) 2020 Utkarsh Gupta <utkarsh@debian.org>
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person
|
7
|
+
obtaining a copy of this software and associated documentation
|
8
|
+
files (the "Software"), to deal in the Software without
|
9
|
+
restriction, including without limitation the rights to use,
|
10
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
copies of the Software, and to permit persons to whom the
|
12
|
+
Software is furnished to do so, subject to the following
|
13
|
+
conditions:
|
14
|
+
|
15
|
+
The above copyright notice and this permission notice shall be
|
16
|
+
included in all copies or substantial portions of the Software.
|
17
|
+
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# GetRoot
|
2
|
+
|
3
|
+
This is essentially written for [RuboCop::Packaging](https://github.com/utkarsh2102/rubocop-packaging)
|
4
|
+
to get the root directory of your git repository at runtime.
|
5
|
+
|
6
|
+
This **only** works on a git repository. Otherwise this won't work, because it
|
7
|
+
essentially looks for the presence of a `.git` directory.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'get_root'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
```bash
|
20
|
+
$ bundle install
|
21
|
+
```
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
```bash
|
26
|
+
$ gem install get_root
|
27
|
+
```
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
You can use `get_root` for your project in the following way:
|
32
|
+
```ruby
|
33
|
+
require 'get_root'
|
34
|
+
|
35
|
+
root_path = GetRoot.path # or GetRoot::path
|
36
|
+
```
|
37
|
+
|
38
|
+
|
39
|
+
Here's a snippet to see how it runs/behaves:
|
40
|
+
```ruby
|
41
|
+
irb(main):001:0> require 'get_root'
|
42
|
+
=> true
|
43
|
+
|
44
|
+
irb(main):002:0> Dir.pwd # to show the current directory.
|
45
|
+
=> "/home/utkarsh/github/rubocop-packaging/spec/rubocop/cop/packaging"
|
46
|
+
|
47
|
+
irb(main):003:0> GetRoot.path # to get the root direcotry of this project
|
48
|
+
=> "/home/utkarsh/github/rubocop-packaging"
|
49
|
+
```
|
50
|
+
|
51
|
+
## Development
|
52
|
+
|
53
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then,
|
54
|
+
run `rake spec` to run the tests. You can also run `bin/console` for an
|
55
|
+
interactive prompt that will allow you to experiment.
|
56
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
As always, bug reports and pull requests are heartily welcomed! 💖
|
61
|
+
This project is intended to be a safe and welcoming space for collaboration.
|
62
|
+
|
63
|
+
## License
|
64
|
+
`get_root` is available as open-source under the
|
65
|
+
[MIT License](https://github.com/utkarsh2102/get_root/blob/master/LICENSE).
|
data/lib/get_root.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "get_root/version"
|
4
|
+
|
5
|
+
module GetRoot # :nodoc:
|
6
|
+
class << self
|
7
|
+
# This method shows the path of the root directory
|
8
|
+
# of a git project.
|
9
|
+
# There, strictly, needs to be a git repository,
|
10
|
+
# otherwise this won't work, because it essentially
|
11
|
+
# looks for the presence of a `.git` directory.
|
12
|
+
def path(count = 0, relative_path = +".", root = nil)
|
13
|
+
if count > 15
|
14
|
+
root = File.expand_path(relative_path)
|
15
|
+
# puts "Assuming root directory to be #{root}. " \
|
16
|
+
# "Please run the same command from the root directory of the project."
|
17
|
+
return root
|
18
|
+
else
|
19
|
+
if Dir.entries(relative_path).include?(".git")
|
20
|
+
root = File.expand_path(relative_path)
|
21
|
+
return root
|
22
|
+
else
|
23
|
+
relative_path.prepend("../")
|
24
|
+
count += 1
|
25
|
+
path(count, relative_path)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: get_root
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Utkarsh Gupta
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-07-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '13.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '13.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop-packaging
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.1.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.1.1
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- utkarsh@debian.org
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- LICENSE
|
63
|
+
- README.md
|
64
|
+
- lib/get_root.rb
|
65
|
+
- lib/get_root/version.rb
|
66
|
+
homepage: https://github.com/utkarsh2102/get_root
|
67
|
+
licenses:
|
68
|
+
- MIT
|
69
|
+
metadata:
|
70
|
+
homepage_uri: https://github.com/utkarsh2102/get_root
|
71
|
+
source_code_uri: https://github.com/utkarsh2102/get_root
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 2.4.0
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubygems_version: 3.1.2
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: Get the root directory of your git repository.
|
91
|
+
test_files: []
|