Sha256: 631e1ced785be8f91033e8210bed3875a8c916dd7e65d101db1ed4befd93b7c3

Contents?: true

Size: 1.02 KB

Versions: 56

Compression:

Stored size: 1.02 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

      def self.parse_manifest(manifest)
        response = Typhoeus.post("#{Bibliothecary.configuration.clojars_parser_host}/project.clj", body: manifest)
        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

56 entries across 56 versions & 1 rubygems

Version Path
bibliothecary-7.3.6 lib/bibliothecary/parsers/clojars.rb
bibliothecary-7.3.5 lib/bibliothecary/parsers/clojars.rb
bibliothecary-7.3.4 lib/bibliothecary/parsers/clojars.rb
bibliothecary-7.3.3 lib/bibliothecary/parsers/clojars.rb
bibliothecary-7.3.2 lib/bibliothecary/parsers/clojars.rb
bibliothecary-7.3.1 lib/bibliothecary/parsers/clojars.rb
bibliothecary-7.3.0 lib/bibliothecary/parsers/clojars.rb
bibliothecary-7.2.1 lib/bibliothecary/parsers/clojars.rb
bibliothecary-7.2.0 lib/bibliothecary/parsers/clojars.rb
bibliothecary-7.1.5 lib/bibliothecary/parsers/clojars.rb
bibliothecary-7.1.4 lib/bibliothecary/parsers/clojars.rb
bibliothecary-7.1.3 lib/bibliothecary/parsers/clojars.rb
bibliothecary-7.1.2 lib/bibliothecary/parsers/clojars.rb
bibliothecary-7.1.1 lib/bibliothecary/parsers/clojars.rb
bibliothecary-7.1.0 lib/bibliothecary/parsers/clojars.rb
bibliothecary-7.0.2 lib/bibliothecary/parsers/clojars.rb
bibliothecary-7.0.1 lib/bibliothecary/parsers/clojars.rb
bibliothecary-7.0.0 lib/bibliothecary/parsers/clojars.rb
bibliothecary-6.12.3 lib/bibliothecary/parsers/clojars.rb
bibliothecary-6.12.2 lib/bibliothecary/parsers/clojars.rb