Class: Bibliothecary::Parsers::CPAN

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

Class Method Summary collapse

Methods included from Analyser

included

Class Method Details

.map_dependencies(hash, key, type) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/bibliothecary/parsers/cpan.rb', line 33

def self.map_dependencies(hash, key, type)
  hash.fetch(key,[]).map do |name, requirement|
    {
      name: name,
      requirement: requirement,
      type: type
    }
  end
end

.parse(filename, path) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/bibliothecary/parsers/cpan.rb', line 9

def self.parse(filename, path)
  if filename.match(/^META\.json$/i)
    file_contents = File.open(path).read
    json = JSON.parse file_contents
    parse_json_manifest(json)
  elsif filename.match(/^META\.yml$/i)
    file_contents = File.open(path).read
    yaml = YAML.load file_contents
    parse_yaml_manifest(yaml)
  else
    []
  end
end

.parse_json_manifest(manifest) ⇒ Object



23
24
25
26
27
# File 'lib/bibliothecary/parsers/cpan.rb', line 23

def self.parse_json_manifest(manifest)
  manifest['prereqs'].map do |group, deps|
    map_dependencies(deps, 'requires', 'runtime')
  end.flatten
end

.parse_yaml_manifest(manifest) ⇒ Object



29
30
31
# File 'lib/bibliothecary/parsers/cpan.rb', line 29

def self.parse_yaml_manifest(manifest)
  map_dependencies(manifest, 'requires', 'runtime')
end