Sha256: fedbb193d4363a80d8380482439b465d91687f4eca4f051d5a6780ece57310d9

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

require "yaml"
require "json"

module Bibliothecary
  module Parsers
    class CPAN
      include Bibliothecary::Analyser

      def self.mapping
        {
          match_filename("META.json", case_insensitive: true) => {
            kind: "manifest",
            parser: :parse_json_manifest,
          },
          match_filename("META.yml", case_insensitive: true) => {
            kind: "manifest",
            parser: :parse_yaml_manifest,
          },
        }
      end

      add_multi_parser(Bibliothecary::MultiParsers::DependenciesCSV)

      def self.parse_json_manifest(file_contents, options: {})
        manifest = JSON.parse file_contents
        manifest["prereqs"].map do |_group, deps|
          map_dependencies(deps, "requires", "runtime", options.fetch(:filename, nil))
        end.flatten
      end

      def self.parse_yaml_manifest(file_contents, options: {})
        manifest = YAML.load file_contents
        map_dependencies(manifest, "requires", "runtime", options.fetch(:filename, nil))
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bibliothecary-12.1.2 lib/bibliothecary/parsers/cpan.rb
bibliothecary-12.1.1 lib/bibliothecary/parsers/cpan.rb
bibliothecary-12.1.0 lib/bibliothecary/parsers/cpan.rb