Module: Dkit::Project

Defined in:
lib/dkit/project.rb

Class Method Summary collapse

Class Method Details

.find_root(from: Dir.pwd) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dkit/project.rb', line 11

def find_root(from: Dir.pwd)
  if (cached = ENV["DKIT_PROJECT_ROOT"]) && !cached.empty? &&
     File.exist?(File.join(cached, DC_CONFIG))
    return cached
  end

  path = Pathname.new(File.realpath(from))
  loop do
    return path.to_s if (path + DC_CONFIG).exist?
    parent = path.parent
    return nil if parent == path
    path = parent
  end
end