Sha256: 5ef84988bd44992a031e6b64c73dfd001a5616566ffe34acd936c7a3aaa2166b

Contents?: true

Size: 1.34 KB

Versions: 21

Compression:

Stored size: 1.34 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
        {
          /^Gemfile$|^gems\.rb$/ => {
            kind: 'manifest',
            parser: :parse_gemfile
          },
          /[A-Za-z0-9_-]+\.gemspec$/ => {
            kind: 'manifest',
            parser: :parse_gemspec
          },
          /^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

21 entries across 21 versions & 1 rubygems

Version Path
bibliothecary-6.2.1 lib/bibliothecary/parsers/rubygems.rb
bibliothecary-6.2.0 lib/bibliothecary/parsers/rubygems.rb
bibliothecary-6.1.0 lib/bibliothecary/parsers/rubygems.rb
bibliothecary-6.0.0 lib/bibliothecary/parsers/rubygems.rb
bibliothecary-5.6.2 lib/bibliothecary/parsers/rubygems.rb
bibliothecary-5.6.1 lib/bibliothecary/parsers/rubygems.rb
bibliothecary-5.6.0 lib/bibliothecary/parsers/rubygems.rb
bibliothecary-5.5.5 lib/bibliothecary/parsers/rubygems.rb
bibliothecary-5.5.4 lib/bibliothecary/parsers/rubygems.rb
bibliothecary-5.5.3 lib/bibliothecary/parsers/rubygems.rb
bibliothecary-5.5.2 lib/bibliothecary/parsers/rubygems.rb
bibliothecary-5.5.1 lib/bibliothecary/parsers/rubygems.rb
bibliothecary-5.5.0 lib/bibliothecary/parsers/rubygems.rb
bibliothecary-5.4.0 lib/bibliothecary/parsers/rubygems.rb
bibliothecary-5.3.4 lib/bibliothecary/parsers/rubygems.rb
bibliothecary-5.3.3 lib/bibliothecary/parsers/rubygems.rb
bibliothecary-5.3.2 lib/bibliothecary/parsers/rubygems.rb
bibliothecary-5.3.1 lib/bibliothecary/parsers/rubygems.rb
bibliothecary-5.3.0 lib/bibliothecary/parsers/rubygems.rb
bibliothecary-5.2.0 lib/bibliothecary/parsers/rubygems.rb