Sha256: 1cbc04977c4c43e3cd28fe95b853e9da6e8509b2b89b143884203bb286253369

Contents?: true

Size: 1.67 KB

Versions: 29

Compression:

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

      add_multi_parser(Bibliothecary::MultiParsers::CycloneDX)
      add_multi_parser(Bibliothecary::MultiParsers::DependenciesCSV)

      def self.parse_mix(file_contents, options: {})
        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|
          {
            name: name,
            requirement: version,
            type: "runtime"
          }
        end
      end

      def self.parse_mix_lock(file_contents, options: {})
        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|
          {
            name: name,
            requirement: info['version'],
            type: "runtime"
          }
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
bibliothecary-8.6.4 lib/bibliothecary/parsers/hex.rb
bibliothecary-8.6.3 lib/bibliothecary/parsers/hex.rb
bibliothecary-8.6.2 lib/bibliothecary/parsers/hex.rb
bibliothecary-8.6.1 lib/bibliothecary/parsers/hex.rb
bibliothecary-8.6.0 lib/bibliothecary/parsers/hex.rb
bibliothecary-8.5.1 lib/bibliothecary/parsers/hex.rb
bibliothecary-8.5.0 lib/bibliothecary/parsers/hex.rb
bibliothecary-8.4.6 lib/bibliothecary/parsers/hex.rb
bibliothecary-8.4.5 lib/bibliothecary/parsers/hex.rb
bibliothecary-8.4.4 lib/bibliothecary/parsers/hex.rb
bibliothecary-8.4.3 lib/bibliothecary/parsers/hex.rb
bibliothecary-8.4.2 lib/bibliothecary/parsers/hex.rb
bibliothecary-8.4.1 lib/bibliothecary/parsers/hex.rb
bibliothecary-8.4.0 lib/bibliothecary/parsers/hex.rb
bibliothecary-8.3.9 lib/bibliothecary/parsers/hex.rb
bibliothecary-8.3.8 lib/bibliothecary/parsers/hex.rb
bibliothecary-8.3.7 lib/bibliothecary/parsers/hex.rb
bibliothecary-8.3.6 lib/bibliothecary/parsers/hex.rb
bibliothecary-8.3.5 lib/bibliothecary/parsers/hex.rb
bibliothecary-8.3.4 lib/bibliothecary/parsers/hex.rb