Sha256: 987ef93071f0d7b4db609b0cad6e833a69f4ad12f3d920b80419409acfc90525

Contents?: true

Size: 783 Bytes

Versions: 2

Compression:

Stored size: 783 Bytes

Contents

class Mona::Package::FindRoot
  include Mona::Mixins

  SYSTEM_ROOT = '/'

  sig do
    params(
      dir: String,
      project_root: T.nilable(String),
    )
    .returns(String)
  end
  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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mona-0.2.3 lib/mona/package/find_root.rb
mona-0.2.2 lib/mona/package/find_root.rb