Sha256: 6768d2a870ed0fbd05fe6fb42008ff56d7d0b1831da2d135812715abf5b871ea

Contents?: true

Size: 1.03 KB

Versions: 7

Compression:

Stored size: 1.03 KB

Contents

require 'yaml'
require 'json'

module Bibliothecary
  module Parsers
    class CPAN
      include Bibliothecary::Analyser

      def self.mapping
        {
          /^META\.json$/i => {
            kind: 'manifest',
            parser: :parse_json_manifest
          },
          /^META\.yml$/i => {
            kind: 'manifest',
            parser: :parse_yaml_manifest
          }
        }
      end

      def self.parse_json_manifest(file_contents)
        manifest = JSON.parse file_contents
        manifest['prereqs'].map do |_group, deps|
          map_dependencies(deps, 'requires', 'runtime')
        end.flatten
      end

      def self.parse_yaml_manifest(file_contents)
        manifest = YAML.load file_contents
        map_dependencies(manifest, 'requires', 'runtime')
      end

      def self.map_dependencies(hash, key, type)
        hash.fetch(key,[]).map do |name, requirement|
          {
            name: name,
            requirement: requirement,
            type: type
          }
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
bibliothecary-5.3.4 lib/bibliothecary/parsers/cpan.rb
bibliothecary-5.3.3 lib/bibliothecary/parsers/cpan.rb
bibliothecary-5.3.2 lib/bibliothecary/parsers/cpan.rb
bibliothecary-5.3.1 lib/bibliothecary/parsers/cpan.rb
bibliothecary-5.3.0 lib/bibliothecary/parsers/cpan.rb
bibliothecary-5.2.0 lib/bibliothecary/parsers/cpan.rb
bibliothecary-5.1.0 lib/bibliothecary/parsers/cpan.rb