Class: Bibliothecary::Parsers::Shard

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

Class Method Summary collapse

Methods included from Analyser

included

Class Method Details

.map_dependencies(hash, key, type) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/bibliothecary/parsers/shard.rb', line 31

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

.parse(filename, path) ⇒ Object



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

def self.parse(filename, path)
  if filename.match(/^shard\.yml$/i)
    file_contents = File.open(path).read
    yaml = YAML.load file_contents
    parse_yaml_manifest(yaml)
  elsif filename.match(/^shard\.lock$/i)
    file_contents = File.open(path).read
    yaml = YAML.load file_contents
    parse_yaml_lockfile(yaml)
  else
    []
  end
end

.parse_yaml_lockfile(manifest) ⇒ Object



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

def self.parse_yaml_lockfile(manifest)
  map_dependencies(manifest, 'shards', 'runtime')
end

.parse_yaml_manifest(manifest) ⇒ Object



26
27
28
29
# File 'lib/bibliothecary/parsers/shard.rb', line 26

def self.parse_yaml_manifest(manifest)
  map_dependencies(manifest, 'dependencies', 'runtime') +
  map_dependencies(manifest, 'development_dependencies', 'runtime')
end