Class: Bibliothecary::Parsers::Rubygems

Inherits:
Object
  • Object
show all
Includes:
Analyser
Defined in:
lib/bibliothecary/parsers/rubygems.rb

Constant Summary collapse

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

Class Method Summary collapse

Methods included from Analyser

included

Class Method Details

.mappingObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/bibliothecary/parsers/rubygems.rb', line 11

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

.parse_gemfile(file_contents) ⇒ Object



42
43
44
45
# File 'lib/bibliothecary/parsers/rubygems.rb', line 42

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

.parse_gemfile_lock(manifest) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bibliothecary/parsers/rubygems.rb', line 28

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

.parse_gemspec(file_contents) ⇒ Object



47
48
49
50
# File 'lib/bibliothecary/parsers/rubygems.rb', line 47

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