class Bibliothecary::Parsers::Clojars

Public Class Methods

mapping() click to toggle source
# File lib/bibliothecary/parsers/clojars.rb, line 9
def self.mapping
  {
    match_filename("project.clj") => {
      kind: "manifest",
      parser: :parse_manifest,
    },
  }
end
parse_manifest(file_contents, options: {}) click to toggle source
# File lib/bibliothecary/parsers/clojars.rb, line 20
def self.parse_manifest(file_contents, options: {}) # rubocop:disable Lint/UnusedMethodArgument
  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|
    Dependency.new(
      name: dependency[0],
      requirement: dependency[1],
      type: "runtime",
    )
  end
end