Sha256: b8dd9f35923f82571f5acb2fccf46deb47c25c1a95bd829f0368e5c5b798cbad

Contents?: true

Size: 1.02 KB

Versions: 5

Compression:

Stored size: 1.02 KB

Contents

require 'yaml'

module Bibliothecary
  module Parsers
    class Pub
      include Bibliothecary::Analyser

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

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

      def self.parse_yaml_lockfile(file_contents, options: {})
        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

5 entries across 5 versions & 1 rubygems

Version Path
bibliothecary-8.2.1 lib/bibliothecary/parsers/pub.rb
bibliothecary-8.2.0 lib/bibliothecary/parsers/pub.rb
bibliothecary-8.1.1 lib/bibliothecary/parsers/pub.rb
bibliothecary-8.1.0 lib/bibliothecary/parsers/pub.rb
bibliothecary-8.0.0 lib/bibliothecary/parsers/pub.rb