Class: Bibliothecary::Parsers::Hackage
- Inherits:
-
Object
- Object
- Bibliothecary::Parsers::Hackage
show all
- Includes:
- Analyser
- Defined in:
- lib/bibliothecary/parsers/hackage.rb
Class Method Summary
collapse
Methods included from Analyser
create_analysis, create_error_analysis, included
Class Method Details
.mapping ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/bibliothecary/parsers/hackage.rb', line 9
def self.mapping
{
match_extension(".cabal") => {
kind: 'manifest',
parser: :parse_cabal
},
match_extension("cabal.config") => {
kind: 'lockfile',
parser: :parse_cabal_config
}
}
end
|
.parse_cabal(file_contents, options: {}) ⇒ Object
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/bibliothecary/parsers/hackage.rb', line 25
def self.parse_cabal(file_contents, options: {})
= {
'Content-Type' => "text/plain;charset=utf-8"
}
response = Typhoeus.post("#{Bibliothecary.configuration.cabal_parser_host}/parse", headers: , body: file_contents)
raise Bibliothecary::RemoteParsingError.new("Http Error #{response.response_code} when contacting: #{Bibliothecary.configuration.cabal_parser_host}/parse", response.response_code) unless response.success?
JSON.parse(response.body, symbolize_names: true)
end
|
.parse_cabal_config(file_contents, options: {}) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/bibliothecary/parsers/hackage.rb', line 36
def self.parse_cabal_config(file_contents, options: {})
manifest = DebControl::ControlFileBase.parse(file_contents)
deps = manifest.first['constraints'].delete("\n").split(',').map(&:strip)
deps.map do |dependency|
dep = dependency.delete("==").split(' ')
{
name: dep[0],
requirement: dep[1] || '*',
type: 'runtime'
}
end
end
|