Sha256: 4fa7e232d97884560b0a610f3f2285ef8c73390b6103004c5e0268189ba71f09

Contents?: true

Size: 807 Bytes

Versions: 4

Compression:

Stored size: 807 Bytes

Contents

class MonoRepoDeps::Package::FindRoot
  include MonoRepoDeps::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, MonoRepoDeps::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

4 entries across 4 versions & 1 rubygems

Version Path
mono_repo_deps-0.2.1 lib/mono_repo_deps/package/find_root.rb
mono_repo_deps-0.2.0 lib/mono_repo_deps/package/find_root.rb
mono_repo_deps-0.1.14 lib/mono_repo_deps/package/find_root.rb
mono_repo_deps-0.1.13 lib/mono_repo_deps/package/find_root.rb