Sha256: 692ae1a976530071a21d68e2723feb95a991f694a316b94b3f127b15c3307b15

Contents?: true

Size: 980 Bytes

Versions: 3

Compression:

Stored size: 980 Bytes

Contents

require 'yaml'

module Bibliothecary
  module Parsers
    class Pub
      include Bibliothecary::Analyser

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

      def self.parse_yaml_manifest(file_contents)
        manifest = YAML.load file_contents
        map_dependencies(manifest, 'dependencies', 'runtime') +
        map_dependencies(manifest, 'dev_dependencies', 'development')
      end

      def self.parse_yaml_lockfile(file_contents)
        manifest = YAML.load file_contents
        manifest.fetch('packages', []).map do |name, dep|
          {
            name: name,
            requirement: dep['version'],
            type: 'runtime'
          }
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bibliothecary-6.3.2 lib/bibliothecary/parsers/pub.rb
bibliothecary-6.3.1 lib/bibliothecary/parsers/pub.rb
bibliothecary-6.3.0 lib/bibliothecary/parsers/pub.rb