Sha256: b1967fc23e55ca45aa7a512a4a9b5b858e4fa95d898d162d56a0d8f00004543c

Contents?: true

Size: 1.28 KB

Versions: 6

Compression:

Stored size: 1.28 KB

Contents

module Bibliothecary
  module Parsers
    class SwiftPM
      include Bibliothecary::Analyser

      def self.mapping
        {
          match_filename("Package.swift", case_insensitive: true) => {
            kind: 'manifest',
            parser: :parse_package_swift
          }
        }
      end

      add_multi_parser(Bibliothecary::MultiParsers::CycloneDX)
      add_multi_parser(Bibliothecary::MultiParsers::DependenciesCSV)
      add_multi_parser(Bibliothecary::MultiParsers::Spdx)

      def self.parse_package_swift(file_contents, options: {})
        response = Typhoeus.post("#{Bibliothecary.configuration.swift_parser_host}/to-json", body: file_contents)
        raise Bibliothecary::RemoteParsingError.new("Http Error #{response.response_code} when contacting: #{Bibliothecary.configuration.swift_parser_host}/to-json", response.response_code) unless response.success?
        json = JSON.parse(response.body)
        json["dependencies"].map do |dependency|
          name = dependency['url'].gsub(/^https?:\/\//, '').gsub(/\.git$/,'')
          version = "#{dependency['version']['lowerBound']} - #{dependency['version']['upperBound']}"
          {
            name: name,
            requirement: version,
            type: 'runtime'
          }
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
bibliothecary-8.7.4 lib/bibliothecary/parsers/swift_pm.rb
bibliothecary-8.7.3 lib/bibliothecary/parsers/swift_pm.rb
bibliothecary-8.7.2 lib/bibliothecary/parsers/swift_pm.rb
bibliothecary-8.7.1 lib/bibliothecary/parsers/swift_pm.rb
bibliothecary-8.7.0 lib/bibliothecary/parsers/swift_pm.rb
bibliothecary-8.6.5 lib/bibliothecary/parsers/swift_pm.rb