Class: Mona::Package::FindRoot

Inherits:
Object
  • Object
show all
Includes:
Mixins
Defined in:
lib/mona/package/find_root.rb

Constant Summary collapse

SYSTEM_ROOT =
'/'

Instance Method Summary collapse

Methods included from Mixins

included

Instance Method Details

#call(dir, project_root) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/mona/package/find_root.rb', line 13

def call(dir, project_root)
  init_dir = dir = File.expand_path(dir)
  project_root = File.expand_path(project_root || SYSTEM_ROOT)

  unless File.exist?(init_dir)
    raise StandardError.new("path '#{init_dir}' does not exist")
  end

  loop do
    project_file_path = File.expand_path(File.join(dir, Mona::PACKAGE_FILENAME))

    if File.exist?(project_file_path)
      return dir
    elsif dir == project_root
      raise StandardError.new("Package.rb for path '#{init_dir}' not found")
    else
      dir = File.expand_path("../", dir)
    end
  end
end