Sha256: 985201b40f8adec55b34c1cecc0ff4a4d61a65c3fec503a35299ad66fadc2e78

Contents?: true

Size: 1.77 KB

Versions: 8

Compression:

Stored size: 1.77 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|
          Dependency.new(
            name: dependency["name"],
            requirement: dependency["version"],
            type: dependency["type"],
          )
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
bibliothecary-11.0.1 lib/bibliothecary/parsers/carthage.rb
bibliothecary-11.0.0 lib/bibliothecary/parsers/carthage.rb
bibliothecary-10.2.4 lib/bibliothecary/parsers/carthage.rb
bibliothecary-10.2.3 lib/bibliothecary/parsers/carthage.rb
bibliothecary-10.2.2 lib/bibliothecary/parsers/carthage.rb
bibliothecary-10.2.0 lib/bibliothecary/parsers/carthage.rb
bibliothecary-10.1.0 lib/bibliothecary/parsers/carthage.rb
bibliothecary-10.0.0 lib/bibliothecary/parsers/carthage.rb