Module: GetRoot
- Defined in:
- lib/get_root.rb,
lib/get_root/version.rb
Overview
:nodoc:
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
-
.path(count = 0, relative_path = +".",, root = nil) ⇒ Object
This method shows the path of the root directory of a git project.
Class Method Details
.path(count = 0, relative_path = +".",, root = nil) ⇒ Object
This method shows the path of the root directory of a git project. There, strictly, needs to be a git repository, otherwise this won’t work, because it essentially looks for the presence of a ‘.git` directory.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/get_root.rb', line 12 def path(count = 0, relative_path = +".", root = nil) if count > 15 root = File.(relative_path) # puts "Assuming root directory to be #{root}. " \ # "Please run the same command from the root directory of the project." return root else if Dir.entries(relative_path).include?(".git") root = File.(relative_path) return root else relative_path.prepend("../") count += 1 path(count, relative_path) end end end |