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

create_analysis, create_error_analysis, 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
  {
    match_filename("mix.exs") => {
      kind: 'manifest',
      parser: :parse_mix
    },
    match_filename("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
33
# File 'lib/bibliothecary/parsers/hex.rb', line 21

def self.parse_mix(manifest)
  response = Typhoeus.post("#{Bibliothecary.configuration.mix_parser_host}/", body: manifest)
  raise Bibliothecary::RemoteParsingError.new("Http Error #{response.response_code} when contacting: #{Bibliothecary.configuration.mix_parser_host}/", response.response_code) unless response.success?
  json = JSON.parse response.body

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

.parse_mix_lock(manifest) ⇒ Object



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

def self.parse_mix_lock(manifest)
  response = Typhoeus.post("#{Bibliothecary.configuration.mix_parser_host}/lock", body: manifest)
  raise Bibliothecary::RemoteParsingError.new("Http Error #{response.response_code} when contacting: #{Bibliothecary.configuration.mix_parser_host}/", response.response_code) unless response.success?
  json = JSON.parse response.body

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