Class: Bibliothecary::Parsers::Elm

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

Class Method Summary collapse

Methods included from Analyser

included

Class Method Details

.map_dependencies(hash, key, type) ⇒ Object



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

def self.map_dependencies(hash, key, type)
  hash.fetch(key,[]).map do |name, requirement|
    {
      name: name,
      requirement: requirement,
      type: type
    }
  end
end

.mappingObject



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

def self.mapping
  {
    /^elm-package\.json$|^elm_dependencies\.json$/ => {
      kind: 'manifest',
      parser: :parse_json_manifest
    },
    /^elm-stuff\/exact-dependencies\.json$/ => {
      kind: 'lockfile',
      parser: :parse_json_lock
    }
  }
end

.parse_json_lock(file_contents) ⇒ Object



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

def self.parse_json_lock(file_contents)
  manifest = JSON.parse file_contents
  manifest.map do |name, requirement|
    {
      name: name,
      requirement: requirement,
      type: 'runtime'
    }
  end
end

.parse_json_manifest(file_contents) ⇒ Object



21
22
23
24
# File 'lib/bibliothecary/parsers/elm.rb', line 21

def self.parse_json_manifest(file_contents)
  manifest = JSON.parse file_contents
  map_dependencies(manifest, 'dependencies', 'runtime')
end