Sha256: 19d2dc662b7defcb0546a53650dd14506c5039b5a2dac6ba58e0a64532b0976a

Contents?: true

Size: 1.23 KB

Versions: 14

Compression:

Stored size: 1.23 KB

Contents

require 'toml-rb'

module Bibliothecary
  module Parsers
    class Cargo
      include Bibliothecary::Analyser

      def self.mapping
        {
          /Cargo\.toml$/ => {
            kind: 'manifest',
            parser: :parse_manifest
          },
          /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

14 entries across 14 versions & 1 rubygems

Version Path
bibliothecary-6.2.1 lib/bibliothecary/parsers/cargo.rb
bibliothecary-6.2.0 lib/bibliothecary/parsers/cargo.rb
bibliothecary-6.1.0 lib/bibliothecary/parsers/cargo.rb
bibliothecary-6.0.0 lib/bibliothecary/parsers/cargo.rb
bibliothecary-5.6.2 lib/bibliothecary/parsers/cargo.rb
bibliothecary-5.6.1 lib/bibliothecary/parsers/cargo.rb
bibliothecary-5.6.0 lib/bibliothecary/parsers/cargo.rb
bibliothecary-5.5.5 lib/bibliothecary/parsers/cargo.rb
bibliothecary-5.5.4 lib/bibliothecary/parsers/cargo.rb
bibliothecary-5.5.3 lib/bibliothecary/parsers/cargo.rb
bibliothecary-5.5.2 lib/bibliothecary/parsers/cargo.rb
bibliothecary-5.5.1 lib/bibliothecary/parsers/cargo.rb
bibliothecary-5.5.0 lib/bibliothecary/parsers/cargo.rb
bibliothecary-5.4.0 lib/bibliothecary/parsers/cargo.rb