Class: Bibliothecary::Parsers::SwiftPM

Inherits:
Object
  • Object
show all
Includes:
Analyser
Defined in:
lib/bibliothecary/parsers/swift_pm.rb

Class Method Summary collapse

Methods included from Analyser

create_analysis, create_error_analysis, included

Class Method Details

.mappingObject



6
7
8
9
10
11
12
13
# 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: {}) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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']}"
    {
      name: name,
      requirement: version,
      type: "runtime",
    }
  end
end