Class: Bibliothecary::Parsers::Clojars

Inherits:
Object
  • Object
show all
Defined in:
lib/bibliothecary/parsers/clojars.rb

Constant Summary collapse

PLATFORM_NAME =
'clojars'

Class Method Summary collapse

Class Method Details

.analyse(folder_path, file_list) ⇒ Object



17
18
19
# File 'lib/bibliothecary/parsers/clojars.rb', line 17

def self.analyse(folder_path, file_list)
  [analyse_manifest(folder_path, file_list)]
end

.analyse_manifest(folder_path, file_list) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bibliothecary/parsers/clojars.rb', line 21

def self.analyse_manifest(folder_path, file_list)
  path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^project\.clj$/) }
  return unless path

  manifest = JSON.parse File.open(path).read

  {
    platform: PLATFORM_NAME,
    path: path,
    dependencies: parse_json_manifest(manifest)
  }
end

.parse(filename, file_contents) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/bibliothecary/parsers/clojars.rb', line 9

def self.parse(filename, file_contents)
  if filename.match(/^project\.clj$/)
    parse_manifest(file_contents)
  else
    []
  end
end

.parse_manifest(manifest) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/bibliothecary/parsers/clojars.rb', line 34

def self.parse_manifest(manifest)
  response = Typhoeus.post("https://clojars-json.herokuapp.com/project.clj", body: manifest)
  json = JSON.parse response.body
  index = json.index("dependencies")

  return [] unless index;
  dependencies = json[index + 1]
  dependencies.map do |dependency|
    {
      name: dependency[0],
      version: dependency[1],
      type: "runtime"
    }
  end
end