Sha256: 139ea75003c8b084fbe7921000f5e8aa21663c76c49d7a540aff29b4068dc4dd

Contents?: true

Size: 1.24 KB

Versions: 18

Compression:

Stored size: 1.24 KB

Contents

module Bibliothecary
  module Parsers
    class Cargo
      include Bibliothecary::Analyser

      def self.mapping
        {
          match_filename("Cargo.toml") => {
            kind: 'manifest',
            parser: :parse_manifest
          },
          match_filename("Cargo.lock") => {
            kind: 'lockfile',
            parser: :parse_lockfile
          }
        }
      end

      def self.parse_manifest(file_contents)
        manifest = Tomlrb.parse(file_contents)
        manifest.fetch('dependencies', []).map do |name, requirement|
          if requirement.respond_to?(:fetch)
            requirement = requirement['version'] or next
          end
          {
            name: name,
            requirement: requirement,
            type: 'runtime'
          }
        end
          .compact
      end

      def self.parse_lockfile(file_contents)
        manifest = Tomlrb.parse(file_contents)
        manifest.fetch('package',[]).map do |dependency|
          next if not dependency['source'] or not dependency['source'].start_with?('registry+')
          {
            name: dependency['name'],
            requirement: dependency['version'],
            type: 'runtime'
          }
        end
          .compact
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
bibliothecary-7.3.6 lib/bibliothecary/parsers/cargo.rb
bibliothecary-7.3.5 lib/bibliothecary/parsers/cargo.rb
bibliothecary-7.3.4 lib/bibliothecary/parsers/cargo.rb
bibliothecary-7.3.3 lib/bibliothecary/parsers/cargo.rb
bibliothecary-7.3.2 lib/bibliothecary/parsers/cargo.rb
bibliothecary-7.3.1 lib/bibliothecary/parsers/cargo.rb
bibliothecary-7.3.0 lib/bibliothecary/parsers/cargo.rb
bibliothecary-7.2.1 lib/bibliothecary/parsers/cargo.rb
bibliothecary-7.2.0 lib/bibliothecary/parsers/cargo.rb
bibliothecary-7.1.5 lib/bibliothecary/parsers/cargo.rb
bibliothecary-7.1.4 lib/bibliothecary/parsers/cargo.rb
bibliothecary-7.1.3 lib/bibliothecary/parsers/cargo.rb
bibliothecary-7.1.2 lib/bibliothecary/parsers/cargo.rb
bibliothecary-7.1.1 lib/bibliothecary/parsers/cargo.rb
bibliothecary-7.1.0 lib/bibliothecary/parsers/cargo.rb
bibliothecary-7.0.2 lib/bibliothecary/parsers/cargo.rb
bibliothecary-7.0.1 lib/bibliothecary/parsers/cargo.rb
bibliothecary-7.0.0 lib/bibliothecary/parsers/cargo.rb