Sha256: 405f11369be18a23e58b3b47dacd55e57436ce52278677ddd9c7f792f5157384

Contents?: true

Size: 1.11 KB

Versions: 35

Compression:

Stored size: 1.11 KB

Contents

require 'json'
require 'typhoeus'

module Bibliothecary
  module Parsers
    class Clojars
      include Bibliothecary::Analyser

      def self.mapping
        {
          match_filename("project.clj") => {
            kind: 'manifest',
            parser: :parse_manifest
          }
        }
      end

      add_multi_parser(Bibliothecary::MultiParsers::DependenciesCSV)

      def self.parse_manifest(file_contents, options: {})
        response = Typhoeus.post("#{Bibliothecary.configuration.clojars_parser_host}/project.clj", body: file_contents)
        raise Bibliothecary::RemoteParsingError.new("Http Error #{response.response_code} when contacting: #{Bibliothecary.configuration.clojars_parser_host}/project.clj", response.response_code) unless response.success?
        json = JSON.parse response.body
        index = json.index("dependencies")

        return [] unless index;
        dependencies = json[index + 1]
        dependencies.map do |dependency|
          {
            name: dependency[0],
            requirement: dependency[1],
            type: "runtime"
          }
        end
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
bibliothecary-8.7.4 lib/bibliothecary/parsers/clojars.rb
bibliothecary-8.7.3 lib/bibliothecary/parsers/clojars.rb
bibliothecary-8.7.2 lib/bibliothecary/parsers/clojars.rb
bibliothecary-8.7.1 lib/bibliothecary/parsers/clojars.rb
bibliothecary-8.7.0 lib/bibliothecary/parsers/clojars.rb
bibliothecary-8.6.5 lib/bibliothecary/parsers/clojars.rb
bibliothecary-8.6.4 lib/bibliothecary/parsers/clojars.rb
bibliothecary-8.6.3 lib/bibliothecary/parsers/clojars.rb
bibliothecary-8.6.2 lib/bibliothecary/parsers/clojars.rb
bibliothecary-8.6.1 lib/bibliothecary/parsers/clojars.rb
bibliothecary-8.6.0 lib/bibliothecary/parsers/clojars.rb
bibliothecary-8.5.1 lib/bibliothecary/parsers/clojars.rb
bibliothecary-8.5.0 lib/bibliothecary/parsers/clojars.rb
bibliothecary-8.4.6 lib/bibliothecary/parsers/clojars.rb
bibliothecary-8.4.5 lib/bibliothecary/parsers/clojars.rb
bibliothecary-8.4.4 lib/bibliothecary/parsers/clojars.rb
bibliothecary-8.4.3 lib/bibliothecary/parsers/clojars.rb
bibliothecary-8.4.2 lib/bibliothecary/parsers/clojars.rb
bibliothecary-8.4.1 lib/bibliothecary/parsers/clojars.rb
bibliothecary-8.4.0 lib/bibliothecary/parsers/clojars.rb