Sha256: b68f56efcaf505781f55e156a80ec4aa27dfea5fc49e8e2a7242d9de0fb547a0

Contents?: true

Size: 1.53 KB

Versions: 54

Compression:

Stored size: 1.53 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,
            related_to: [ 'manifest', 'lockfile' ]
          },
          match_extension(".gemspec") => {
            kind: 'manifest',
            parser: :parse_gemspec,
            related_to: [ 'manifest', 'lockfile' ]
          },
          match_filenames("Gemfile.lock", "gems.locked") => {
            kind: 'lockfile',
            parser: :parse_gemfile_lock,
            related_to: [ 'manifest', 'lockfile' ]
          }
        }
      end

      def self.parse_gemfile_lock(manifest)
        manifest.lines(chomp: true).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

54 entries across 54 versions & 1 rubygems

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