Sha256: e483cae0a7eb4d8f7f3d077f09c8ee5500f6d461fb36bb941c49980afbbc2a99

Contents?: true

Size: 1.76 KB

Versions: 6

Compression:

Stored size: 1.76 KB

Contents

module Bibliothecary
  module Parsers
    class Carthage
      include Bibliothecary::Analyser

      def self.mapping
        {
          match_filename("Cartfile") => {
            kind: "manifest",
            parser: :parse_cartfile,
          },
          match_filename("Cartfile.private") => {
            kind: "manifest",
            parser: :parse_cartfile_private,
          },
          match_filename("Cartfile.resolved") => {
            kind: "lockfile",
            parser: :parse_cartfile_resolved,
          },
        }
      end

      add_multi_parser(Bibliothecary::MultiParsers::DependenciesCSV)

      def self.parse_cartfile(file_contents, options: {}) # rubocop:disable Lint/UnusedMethodArgument
        map_dependencies(file_contents, "cartfile")
      end

      def self.parse_cartfile_private(file_contents, options: {}) # rubocop:disable Lint/UnusedMethodArgument
        map_dependencies(file_contents, "cartfile.private")
      end

      def self.parse_cartfile_resolved(file_contents, options: {}) # rubocop:disable Lint/UnusedMethodArgument
        map_dependencies(file_contents, "cartfile.resolved")
      end

      def self.map_dependencies(manifest, path)
        response = Typhoeus.post("#{Bibliothecary.configuration.carthage_parser_host}/#{path}", params: { body: manifest })
        raise Bibliothecary::RemoteParsingError.new("Http Error #{response.response_code} when contacting: #{Bibliothecary.configuration.carthage_parser_host}/#{path}", response.response_code) unless response.success?
        json = JSON.parse(response.body)

        json.map do |dependency|
          {
            name: dependency["name"],
            requirement: dependency["version"],
            type: dependency["type"],
          }
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
bibliothecary-9.1.0 lib/bibliothecary/parsers/carthage.rb
bibliothecary-9.0.0 lib/bibliothecary/parsers/carthage.rb
bibliothecary-8.8.1 lib/bibliothecary/parsers/carthage.rb
bibliothecary-8.7.7 lib/bibliothecary/parsers/carthage.rb
bibliothecary-8.7.6 lib/bibliothecary/parsers/carthage.rb
bibliothecary-8.7.5 lib/bibliothecary/parsers/carthage.rb