class Bibliothecary::Parsers::Hex

Public Class Methods

mapping() click to toggle source
# File lib/bibliothecary/parsers/hex.rb, line 8
def self.mapping
  {
    match_filename("mix.exs") => {
      kind: "manifest",
      parser: :parse_mix,
    },
    match_filename("mix.lock") => {
      kind: "lockfile",
      parser: :parse_mix_lock,
    },
  }
end
parse_mix(file_contents, options: {}) click to toggle source
# File lib/bibliothecary/parsers/hex.rb, line 25
def self.parse_mix(file_contents, options: {}) # rubocop:disable Lint/UnusedMethodArgument
  response = Typhoeus.post("#{Bibliothecary.configuration.mix_parser_host}/", body: file_contents)
  raise Bibliothecary::RemoteParsingError.new("Http Error #{response.response_code} when contacting: #{Bibliothecary.configuration.mix_parser_host}/", response.response_code) unless response.success?
  json = JSON.parse response.body

  json.map do |name, version|
    Dependency.new(
      name: name,
      requirement: version,
      type: "runtime",
    )
  end
end
parse_mix_lock(file_contents, options: {}) click to toggle source
# File lib/bibliothecary/parsers/hex.rb, line 39
def self.parse_mix_lock(file_contents, options: {}) # rubocop:disable Lint/UnusedMethodArgument
  response = Typhoeus.post("#{Bibliothecary.configuration.mix_parser_host}/lock", body: file_contents)
  raise Bibliothecary::RemoteParsingError.new("Http Error #{response.response_code} when contacting: #{Bibliothecary.configuration.mix_parser_host}/", response.response_code) unless response.success?
  json = JSON.parse response.body

  json.map do |name, info|
    Dependency.new(
      name: name,
      requirement: info["version"],
      type: "runtime",
    )
  end
end