Class: Bibliothecary::Parsers::CocoaPods

Inherits:
Object
  • Object
show all
Includes:
Analyser
Defined in:
lib/bibliothecary/parsers/cocoapods.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

.parse(filename, path) ⇒ Object



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

def self.parse(filename, path)
  if filename.match(/^Podfile$/)
    file_contents = File.open(path).read
    manifest = Gemnasium::Parser.send(:podfile, file_contents)
    parse_manifest(manifest)
  elsif filename.match(/^[A-Za-z0-9_-]+\.podspec$/)
    file_contents = File.open(path).read
    manifest = Gemnasium::Parser.send(:podspec, file_contents)
    parse_manifest(manifest)
  elsif filename.match(/^Podfile\.lock$/)
    file_contents = File.open(path).read
    manifest = YAML.load file_contents
    parse_podfile_lock(manifest)
  elsif filename.match(/^[A-Za-z0-9_-]+\.podspec.json$/)
    file_contents = File.open(path).read
    json = JSON.parse(file_contents)
    parse_json_manifest(json)
  else
    []
  end
end

.parse_json_manifest(manifest) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/bibliothecary/parsers/cocoapods.rb', line 56

def self.parse_json_manifest(manifest)
  manifest['dependencies'].inject([]) do |deps, dep|
    deps.push({
      name: dep[0],
      requirement: dep[1],
      type: 'runtime'
    })
  end.uniq
end

.parse_manifest(manifest) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/bibliothecary/parsers/cocoapods.rb', line 46

def self.parse_manifest(manifest)
  manifest.dependencies.inject([]) do |deps, dep|
    deps.push({
      name: dep.name,
      requirement: dep.requirement.to_s,
      type: dep.type
    })
  end.uniq
end

.parse_podfile_lock(manifest) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/bibliothecary/parsers/cocoapods.rb', line 34

def self.parse_podfile_lock(manifest)
  manifest['PODS'].map do |row|
    pod = row.is_a?(String) ? row : row.keys.first
    match = pod.match(/(.+?)\s\((.+?)\)/i)
    {
      name: match[1].split('/').first,
      requirement: match[2],
      type: 'runtime'
    }
  end.compact
end