Sha256: 53f679f8c080bd258c4aac7933d4beeff373f6922a13b611d7a855944ff7a0b8

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

require 'gemnasium/parser'

module Bibliothecary
  module Parsers
    class Rubygems
      include Bibliothecary::Analyser

      NAME_VERSION = '(?! )(.*?)(?: \(([^-]*)(?:-(.*))?\))?'.freeze
      NAME_VERSION_4 = /^ {4}#{NAME_VERSION}$/

      def self.mapping
        {
          match_filenames("Gemfile", "gems.rb") => {
            kind: 'manifest',
            parser: :parse_gemfile
          },
          match_extension(".gemspec") => {
            kind: 'manifest',
            parser: :parse_gemspec,
            can_have_lockfile: false
          },
          match_filenames("Gemfile.lock", "gems.locked") => {
            kind: 'lockfile',
            parser: :parse_gemfile_lock
          }
        }
      end

      def self.parse_gemfile_lock(manifest)
        manifest.split("\n").map do |line|
          match = line.match(NAME_VERSION_4)
          next unless match
          name = match[1]
          version = match[2].gsub(/\(|\)/,'')
          {
            name: name,
            requirement: version,
            type: 'runtime'
          }
        end.compact
      end

      def self.parse_gemfile(file_contents)
        manifest = Gemnasium::Parser.send(:gemfile, file_contents)
        parse_ruby_manifest(manifest)
      end

      def self.parse_gemspec(file_contents)
        manifest = Gemnasium::Parser.send(:gemspec, file_contents)
        parse_ruby_manifest(manifest)
      end


    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bibliothecary-6.4.0 lib/bibliothecary/parsers/rubygems.rb