Sha256: ec8e348f5795fe4c2e51e9698a5094d0af0083dc8ddd2b43d0fe8b33df4494d8
Contents?: true
Size: 1.38 KB
Versions: 55
Compression:
Stored size: 1.38 KB
Contents
require "json" require 'deb_control' module Bibliothecary module Parsers class Hackage include Bibliothecary::Analyser def self.mapping { match_extension(".cabal") => { kind: 'manifest', parser: :parse_cabal }, match_extension("cabal.config") => { kind: 'lockfile', parser: :parse_cabal_config } } end def self.parse_cabal(file_contents) headers = { 'Content-Type' => "text/plain;charset=utf-8" } response = Typhoeus.post("#{Bibliothecary.configuration.cabal_parser_host}/parse", headers: headers, body: file_contents) raise Bibliothecary::RemoteParsingError.new("Http Error #{response.response_code} when contacting: #{Bibliothecary.configuration.cabal_parser_host}/parse", response.response_code) unless response.success? JSON.parse(response.body, symbolize_names: true) end def self.parse_cabal_config(file_contents) manifest = DebControl::ControlFileBase.parse(file_contents) deps = manifest.first['constraints'].delete("\n").split(',').map(&:strip) deps.map do |dependency| dep = dependency.delete("==").split(' ') { name: dep[0], requirement: dep[1] || '*', type: 'runtime' } end end end end end
Version data entries
55 entries across 55 versions & 1 rubygems