Sha256: 888c3cbca50bd56e42d7903dccf6d98eff96a01783e3a9d5b401dc2d5e434724

Contents?: true

Size: 1.22 KB

Versions: 29

Compression:

Stored size: 1.22 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)

      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

29 entries across 29 versions & 1 rubygems

Version Path
bibliothecary-8.6.4 lib/bibliothecary/parsers/swift_pm.rb
bibliothecary-8.6.3 lib/bibliothecary/parsers/swift_pm.rb
bibliothecary-8.6.2 lib/bibliothecary/parsers/swift_pm.rb
bibliothecary-8.6.1 lib/bibliothecary/parsers/swift_pm.rb
bibliothecary-8.6.0 lib/bibliothecary/parsers/swift_pm.rb
bibliothecary-8.5.1 lib/bibliothecary/parsers/swift_pm.rb
bibliothecary-8.5.0 lib/bibliothecary/parsers/swift_pm.rb
bibliothecary-8.4.6 lib/bibliothecary/parsers/swift_pm.rb
bibliothecary-8.4.5 lib/bibliothecary/parsers/swift_pm.rb
bibliothecary-8.4.4 lib/bibliothecary/parsers/swift_pm.rb
bibliothecary-8.4.3 lib/bibliothecary/parsers/swift_pm.rb
bibliothecary-8.4.2 lib/bibliothecary/parsers/swift_pm.rb
bibliothecary-8.4.1 lib/bibliothecary/parsers/swift_pm.rb
bibliothecary-8.4.0 lib/bibliothecary/parsers/swift_pm.rb
bibliothecary-8.3.9 lib/bibliothecary/parsers/swift_pm.rb
bibliothecary-8.3.8 lib/bibliothecary/parsers/swift_pm.rb
bibliothecary-8.3.7 lib/bibliothecary/parsers/swift_pm.rb
bibliothecary-8.3.6 lib/bibliothecary/parsers/swift_pm.rb
bibliothecary-8.3.5 lib/bibliothecary/parsers/swift_pm.rb
bibliothecary-8.3.4 lib/bibliothecary/parsers/swift_pm.rb