Sha256: 646f64e50339e17fa9ace1e5623fe8336f6b2e631f2866616771f8959ba9967c

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

require "yaml"

module Bibliothecary
  module Parsers
    class Shard
      include Bibliothecary::Analyser

      def self.mapping
        {
          match_filename("shard.yml", case_insensitive: true) => {
            kind: "manifest",
            parser: :parse_yaml_manifest,
          },
          match_filename("shard.lock", case_insensitive: true) => {
            kind: "lockfile",
            parser: :parse_yaml_lockfile,
          },
        }
      end

      add_multi_parser(Bibliothecary::MultiParsers::DependenciesCSV)

      def self.parse_yaml_lockfile(file_contents, options: {}) # rubocop:disable Lint/UnusedMethodArgument
        manifest = YAML.load file_contents
        map_dependencies(manifest, "shards", "runtime")
      end

      def self.parse_yaml_manifest(file_contents, options: {}) # rubocop:disable Lint/UnusedMethodArgument
        manifest = YAML.load file_contents
        map_dependencies(manifest, "dependencies", "runtime") +
        map_dependencies(manifest, "development_dependencies", "runtime")
      end

      def self.map_dependencies(hash, key, type)
        hash.fetch(key,[]).map do |name, requirement|
          Dependency.new(
            name: name,
            requirement: requirement["version"] || "*",
            type: type,
          )
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bibliothecary-10.1.0 lib/bibliothecary/parsers/shard.rb
bibliothecary-10.0.0 lib/bibliothecary/parsers/shard.rb