Sha256: 811abd4b90d217414ae70c84b456c0207475106d1771033d8c6da4237576e20d

Contents?: true

Size: 1.49 KB

Versions: 56

Compression:

Stored size: 1.49 KB

Contents

require 'json'

module Bibliothecary
  module Parsers
    class Hex
      include Bibliothecary::Analyser

      def self.mapping
        {
          match_filename("mix.exs") => {
            kind: 'manifest',
            parser: :parse_mix
          },
          match_filename("mix.lock") => {
            kind: 'lockfile',
            parser: :parse_mix_lock
          }
        }
      end

      def self.parse_mix(manifest)
        response = Typhoeus.post("#{Bibliothecary.configuration.mix_parser_host}/", body: manifest)
        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|
          {
            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)
        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|
          {
            name: name,
            requirement: info['version'],
            type: "runtime"
          }
        end
      end
    end
  end
end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
bibliothecary-6.8.9 lib/bibliothecary/parsers/hex.rb
bibliothecary-6.8.8 lib/bibliothecary/parsers/hex.rb
bibliothecary-6.8.7 lib/bibliothecary/parsers/hex.rb
bibliothecary-6.8.6 lib/bibliothecary/parsers/hex.rb
bibliothecary-6.8.5 lib/bibliothecary/parsers/hex.rb
bibliothecary-6.8.4 lib/bibliothecary/parsers/hex.rb
bibliothecary-6.8.3 lib/bibliothecary/parsers/hex.rb
bibliothecary-6.8.2 lib/bibliothecary/parsers/hex.rb
bibliothecary-6.8.1 lib/bibliothecary/parsers/hex.rb
bibliothecary-6.8.0 lib/bibliothecary/parsers/hex.rb
bibliothecary-6.7.4 lib/bibliothecary/parsers/hex.rb
bibliothecary-6.7.3 lib/bibliothecary/parsers/hex.rb
bibliothecary-6.7.2 lib/bibliothecary/parsers/hex.rb
bibliothecary-6.7.1 lib/bibliothecary/parsers/hex.rb
bibliothecary-6.6.0 lib/bibliothecary/parsers/hex.rb
bibliothecary-6.4.0 lib/bibliothecary/parsers/hex.rb