Sha256: d15083fb9e243a98d903c619936ba4d311efe7911830f18a1c3e7d5d7323203d

Contents?: true

Size: 880 Bytes

Versions: 3

Compression:

Stored size: 880 Bytes

Contents

# frozen_string_literal: true

module Bibliothecary
  class PurlUtil
    # If a purl type (key) exists, it will be used in a manifest for
    # the key's value. If not, it's ignored.
    #
    # https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst
    PURL_TYPE_MAPPING = {
      "golang" => :go,
      "maven" => :maven,
      "npm" => :npm,
      "cargo" => :cargo,
      "composer" => :packagist,
      "conda" => :conda,
      "cran" => :cran,
      "gem" => :rubygems,
      "nuget" => :nuget,
      "pypi" => :pypi,
    }.freeze

    # @param purl [PackageURL]
    # @return [String] The properly namespaced package name
    def self.full_name(purl)
      return nil if purl.nil?

      parts = [purl.namespace, purl.name].compact

      case purl.type
      when "maven"
        parts.join(":")
      else
        parts.join("/")
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bibliothecary-12.1.2 lib/bibliothecary/purl_util.rb
bibliothecary-12.1.1 lib/bibliothecary/purl_util.rb
bibliothecary-12.1.0 lib/bibliothecary/purl_util.rb