Sha256: 7003ae3071a13fde54bfd0748e4fd7ee44572e17c8d6af74932f65701ed5a6d1

Contents?: true

Size: 1.22 KB

Versions: 23

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

23 entries across 23 versions & 1 rubygems

Version Path
ree-1.0.32 lib/ree/core/packages_detector.rb
ree-1.0.31 lib/ree/core/packages_detector.rb
ree-1.0.30 lib/ree/core/packages_detector.rb
ree-1.0.29 lib/ree/core/packages_detector.rb
ree-1.0.28 lib/ree/core/packages_detector.rb
ree-1.0.27 lib/ree/core/packages_detector.rb
ree-1.0.26 lib/ree/core/packages_detector.rb
ree-1.0.25 lib/ree/core/packages_detector.rb
ree-1.0.24 lib/ree/core/packages_detector.rb
ree-1.0.23 lib/ree/core/packages_detector.rb
ree-1.0.22 lib/ree/core/packages_detector.rb
ree-1.0.21 lib/ree/core/packages_detector.rb
ree-1.0.20 lib/ree/core/packages_detector.rb
ree-1.0.19 lib/ree/core/packages_detector.rb
ree-1.0.18 lib/ree/core/packages_detector.rb
ree-1.0.17 lib/ree/core/packages_detector.rb
ree-1.0.16 lib/ree/core/packages_detector.rb
ree-1.0.15 lib/ree/core/packages_detector.rb
ree-1.0.14 lib/ree/core/packages_detector.rb
ree-1.0.13 lib/ree/core/packages_detector.rb