Sha256: 9fb90d8ab31afc221006637516f6bbd32060d94ec5ac62eeb0b7442ff1682d9d

Contents?: true

Size: 1.22 KB

Versions: 15

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

require 'pathname'

class Ree::PackagesDetector
  # @param [String] dir Packages root dir
  # @return [ArrayOf[{name: String, entry_path: String, package_schema_path: String, gem_name: Nilor[String]}]]
  def call(dir, gem_name = nil)
    if !Dir.exist?(dir)
      raise Ree::Error.new("dir does not exist: #{dir}", :invalid_dir)
    end

    files = File.join(dir, "**/", Ree::PACKAGE_SCHEMA_FILE)
    names = {}

    Dir[files].map do |file|
      package_schema_path = Pathname
        .new(file)
        .relative_path_from(Pathname.new(dir))
        .to_s

      name = package_schema_path.split('/')[-2]
      entry_path = Ree::PathHelper.package_entry_path(package_schema_path)

      if !File.exist?(File.join(dir, entry_path))
        Ree.logger.error("Entry file does not exist for '#{name}' package: #{entry_path}")
      end

      if names.has_key?(name)
        raise Ree::Error.new("package '#{name}' has duplicate defintions.\n\t1) #{names[name]},\n\t2) #{entry_path}", :duplicate_package)
      end

      names[name] = entry_path

      {
        name: name.to_sym,
        entry_path: entry_path,
        package_schema_path: package_schema_path,
        gem_name: gem_name
      }
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
ree-1.0.47 lib/ree/core/packages_detector.rb
ree-1.0.46 lib/ree/core/packages_detector.rb
ree-1.0.45 lib/ree/core/packages_detector.rb
ree-1.0.44 lib/ree/core/packages_detector.rb
ree-1.0.43 lib/ree/core/packages_detector.rb
ree-1.0.42 lib/ree/core/packages_detector.rb
ree-1.0.41 lib/ree/core/packages_detector.rb
ree-1.0.40 lib/ree/core/packages_detector.rb
ree-1.0.39 lib/ree/core/packages_detector.rb
ree-1.0.38 lib/ree/core/packages_detector.rb
ree-1.0.37 lib/ree/core/packages_detector.rb
ree-1.0.36 lib/ree/core/packages_detector.rb
ree-1.0.35 lib/ree/core/packages_detector.rb
ree-1.0.34 lib/ree/core/packages_detector.rb
ree-1.0.33 lib/ree/core/packages_detector.rb