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

create_analysis, create_error_analysis, included

Class Method Details

.mappingObject



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

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

.parse_gemfile(file_contents) ⇒ Object



45
46
47
48
# File 'lib/bibliothecary/parsers/rubygems.rb', line 45

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

.parse_gemfile_lock(manifest) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bibliothecary/parsers/rubygems.rb', line 31

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

.parse_gemspec(file_contents) ⇒ Object



50
51
52
53
# File 'lib/bibliothecary/parsers/rubygems.rb', line 50

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