class Bibliothecary::Parsers::SwiftPM

Public Class Methods

mapping() click to toggle source
# File lib/bibliothecary/parsers/swift_pm.rb, line 6
def self.mapping
  {
    match_filename("Package.swift", case_insensitive: true) => {
      kind: "manifest",
      parser: :parse_package_swift,
    },
  }
end
parse_package_swift(file_contents, options: {}) click to toggle source
# File lib/bibliothecary/parsers/swift_pm.rb, line 19
def self.parse_package_swift(file_contents, options: {}) # rubocop:disable Lint/UnusedMethodArgument
  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']}"
    Dependency.new(
      name: name,
      requirement: version,
      type: "runtime",
    )
  end
end