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(file_contents, options: {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/bibliothecary/parsers/hex.rb', line 25

def self.parse_mix(file_contents, options: {})
  response = Typhoeus.post("#{Bibliothecary.configuration.mix_parser_host}/", body: file_contents)
  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(file_contents, options: {}) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/bibliothecary/parsers/hex.rb', line 39

def self.parse_mix_lock(file_contents, options: {})
  response = Typhoeus.post("#{Bibliothecary.configuration.mix_parser_host}/lock", body: file_contents)
  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