Sha256: 29a7f3a79c2c44ce4c98ae0981c925d711649fd5037304238b60809c303ce33f

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

require 'json'

module Bibliothecary
  module Parsers
    class Hex
      include Bibliothecary::Analyser

      def self.parse(filename, file_contents)
        if filename.match(/^mix\.exs$/)
          parse_mix(file_contents)
        elsif filename.match(/^mix\.lock$/)
          parse_mix_lock(file_contents)
        else
          []
        end
      end

      def self.parse_mix(manifest)
        response = Typhoeus.post("https://mix-deps-json.herokuapp.com/", body: manifest)
        json = JSON.parse response.body

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

      def self.parse_mix_lock(manifest)
        response = Typhoeus.post("https://mix-deps-json.herokuapp.com/lock", body: manifest)
        json = JSON.parse response.body

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bibliothecary-2.0.1 lib/bibliothecary/parsers/hex.rb
bibliothecary-2.0.0 lib/bibliothecary/parsers/hex.rb