Sha256: dff58d3b2b216b26da2fb6695f65435e883c6a3a7e8675f74436ec42e669bdaf

Contents?: true

Size: 1.2 KB

Versions: 35

Compression:

Stored size: 1.2 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: {})
        manifest = YAML.load file_contents
        map_dependencies(manifest, 'shards', 'runtime')
      end

      def self.parse_yaml_manifest(file_contents, options: {})
        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|
          {
            name: name,
            requirement: requirement['version'] || '*',
            type: type
          }
        end
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
bibliothecary-8.7.4 lib/bibliothecary/parsers/shard.rb
bibliothecary-8.7.3 lib/bibliothecary/parsers/shard.rb
bibliothecary-8.7.2 lib/bibliothecary/parsers/shard.rb
bibliothecary-8.7.1 lib/bibliothecary/parsers/shard.rb
bibliothecary-8.7.0 lib/bibliothecary/parsers/shard.rb
bibliothecary-8.6.5 lib/bibliothecary/parsers/shard.rb
bibliothecary-8.6.4 lib/bibliothecary/parsers/shard.rb
bibliothecary-8.6.3 lib/bibliothecary/parsers/shard.rb
bibliothecary-8.6.2 lib/bibliothecary/parsers/shard.rb
bibliothecary-8.6.1 lib/bibliothecary/parsers/shard.rb
bibliothecary-8.6.0 lib/bibliothecary/parsers/shard.rb
bibliothecary-8.5.1 lib/bibliothecary/parsers/shard.rb
bibliothecary-8.5.0 lib/bibliothecary/parsers/shard.rb
bibliothecary-8.4.6 lib/bibliothecary/parsers/shard.rb
bibliothecary-8.4.5 lib/bibliothecary/parsers/shard.rb
bibliothecary-8.4.4 lib/bibliothecary/parsers/shard.rb
bibliothecary-8.4.3 lib/bibliothecary/parsers/shard.rb
bibliothecary-8.4.2 lib/bibliothecary/parsers/shard.rb
bibliothecary-8.4.1 lib/bibliothecary/parsers/shard.rb
bibliothecary-8.4.0 lib/bibliothecary/parsers/shard.rb