Class: Bibliothecary::Parsers::Hex

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

Class Method Summary collapse

Methods included from Analyser

included

Class Method Details

.mappingObject



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

def self.mapping
  {
    /^mix\.exs$/ => {
      kind: 'manifest',
      parser: :parse_mix
    },
    /^mix\.lock$/ => {
      kind: 'lockfile',
      parser: :parse_mix_lock
    }
  }
end

.parse_mix(manifest) ⇒ Object



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

def self.parse_mix(manifest)
  response = Typhoeus.post("https://mix.libraries.io/", body: manifest)
  json = JSON.parse response.body

  json.map do |name, version|
    {
      name: name,
      version: version,
      type: "runtime"
    }
  end
end

.parse_mix_lock(manifest) ⇒ Object



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

def self.parse_mix_lock(manifest)
  response = Typhoeus.post("https://mix.libraries.io/lock", body: manifest)
  json = JSON.parse response.body

  json.map do |name, info|
    {
      name: name,
      version: info['version'],
      type: "runtime"
    }
  end
end