Class: Mona::Project::FindRoot

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

Constant Summary collapse

SYSTEM_ROOT =
'/'

Instance Method Summary collapse

Methods included from Mixins

included

Instance Method Details

#call(dir) ⇒ Object



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

def call(dir)
  init_dir = dir = File.expand_path(dir)

  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::PROJECT_FILENAME))

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