Sha256: 8b666e7a52257a6d3a01f774a1496776bab9418ef8b98c9becf09a3c7c9d326f

Contents?: true

Size: 1.04 KB

Versions: 21

Compression:

Stored size: 1.04 KB

Contents

require 'yaml'

module Bibliothecary
  module Parsers
    class Shard
      include Bibliothecary::Analyser

      def self.mapping
        {
          /^shard\.yml$/i => {
            kind: 'manifest',
            parser: :parse_yaml_manifest
          },
          /^shard\.lock$/i => {
            kind: 'lockfile',
            parser: :parse_yaml_lockfile
          }
        }
      end

      def self.parse_yaml_lockfile(file_contents)
        manifest = YAML.load file_contents
        map_dependencies(manifest, 'shards', 'runtime')
      end

      def self.parse_yaml_manifest(file_contents)
        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

21 entries across 21 versions & 1 rubygems

Version Path
bibliothecary-6.2.1 lib/bibliothecary/parsers/shard.rb
bibliothecary-6.2.0 lib/bibliothecary/parsers/shard.rb
bibliothecary-6.1.0 lib/bibliothecary/parsers/shard.rb
bibliothecary-6.0.0 lib/bibliothecary/parsers/shard.rb
bibliothecary-5.6.2 lib/bibliothecary/parsers/shard.rb
bibliothecary-5.6.1 lib/bibliothecary/parsers/shard.rb
bibliothecary-5.6.0 lib/bibliothecary/parsers/shard.rb
bibliothecary-5.5.5 lib/bibliothecary/parsers/shard.rb
bibliothecary-5.5.4 lib/bibliothecary/parsers/shard.rb
bibliothecary-5.5.3 lib/bibliothecary/parsers/shard.rb
bibliothecary-5.5.2 lib/bibliothecary/parsers/shard.rb
bibliothecary-5.5.1 lib/bibliothecary/parsers/shard.rb
bibliothecary-5.5.0 lib/bibliothecary/parsers/shard.rb
bibliothecary-5.4.0 lib/bibliothecary/parsers/shard.rb
bibliothecary-5.3.4 lib/bibliothecary/parsers/shard.rb
bibliothecary-5.3.3 lib/bibliothecary/parsers/shard.rb
bibliothecary-5.3.2 lib/bibliothecary/parsers/shard.rb
bibliothecary-5.3.1 lib/bibliothecary/parsers/shard.rb
bibliothecary-5.3.0 lib/bibliothecary/parsers/shard.rb
bibliothecary-5.2.0 lib/bibliothecary/parsers/shard.rb