Sha256: 3ace8f9ec1dbb0605b2da5a4225a5e522ec5402913760df5feaf1ea187e01044

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

require 'json'

module Bibliothecary
  module Parsers
    class Hex
      include Bibliothecary::Analyser

      def self.mapping
        {
          /^mix\.exs$|.*\/mix\.exs$/ => {
            kind: 'manifest',
            parser: :parse_mix
          },
          /^mix\.lock$|.*\/mix\.lock$/ => {
            kind: 'lockfile',
            parser: :parse_mix_lock
          }
        }
      end

      def self.parse_mix(manifest)
        response = Typhoeus.post("#{Bibliothecary.configuration.mix_parser_host}/", body: manifest)
        json = JSON.parse response.body

        json.map do |name, version|
          {
            name: name,
            requirement: version,
            type: "runtime"
          }
        end
      end

      def self.parse_mix_lock(manifest)
        response = Typhoeus.post("#{Bibliothecary.configuration.mix_parser_host}/lock", body: manifest)
        json = JSON.parse response.body

        json.map do |name, info|
          {
            name: name,
            requirement: info['version'],
            type: "runtime"
          }
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bibliothecary-6.3.1 lib/bibliothecary/parsers/hex.rb
bibliothecary-6.3.0 lib/bibliothecary/parsers/hex.rb