Class: Librarian::Puppet::Lockfile::Parser

Inherits:
Lockfile::Parser
  • Object
show all
Includes:
Util
Defined in:
lib/librarian/puppet/lockfile.rb

Overview

Extend the parser to normalize module names in old .lock files, converting / to -

Instance Method Summary collapse

Methods included from Util

#clean_uri, #cp_r, #debug, #info, #module_name, #normalize_name, #rsync?, #warn

Instance Method Details

#compile(sources_ast) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/librarian/puppet/lockfile.rb', line 58

def compile(sources_ast)
  manifests = compile_placeholder_manifests(sources_ast)
  manifests = manifests.map do |name, manifest|
    manifest.dependencies.map do |d|
      environment.dsl_class.dependency_type.new(d.name, d.requirement, manifests[d.name].source, name)
    end
    real = Manifest.new(manifest.source, manifest.name)
    real.version = manifest.version
    real.dependencies = manifest.dependencies
    real
  end
  ManifestSet.sort(manifests)
end

#compile_placeholder_manifests(sources_ast) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/librarian/puppet/lockfile.rb', line 39

def compile_placeholder_manifests(sources_ast)
  manifests = {}
  sources_ast.each do |source_ast|
    source_type = source_ast[:type]
    source = source_type.from_lock_options(environment, source_ast[:options])
    source_ast[:manifests].each do |manifest_name, manifest_ast|
      manifests[manifest_name] = ManifestPlaceholder.new(
        source,
        manifest_name,
        manifest_ast[:version],
        manifest_ast[:dependencies].map do |k, v|
          environment.dsl_class.dependency_type.new(k, v, nil, manifest_name)
        end,
      )
    end
  end
  manifests
end

#extract_and_parse_dependencies(lines, manifests_index) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/librarian/puppet/lockfile.rb', line 21

def extract_and_parse_dependencies(lines, manifests_index)
  # when looking up in manifests_index normalize the name beforehand
  class << manifests_index
    include Librarian::Puppet::Util
    alias_method :old_lookup, :[]
    define_method(:[]) { |k| old_lookup(normalize_name(k)) }
  end
  dependencies = []
  while lines.first =~ %r{^ {2}([\w\-/]+)(?: \((.*)\))?$}
    lines.shift
    name = ::Regexp.last_match(1)
    requirement = ::Regexp.last_match(2).split(/,\s*/)
    dependencies << environment.dsl_class.dependency_type.new(name, requirement, manifests_index[name].source,
                                                              'lockfile')
  end
  dependencies
end

#extract_and_parse_sources(lines) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/librarian/puppet/lockfile.rb', line 11

def extract_and_parse_sources(lines)
  sources = super
  sources.each do |source|
    source[:manifests] = Hash[source[:manifests].map do |name, manifest|
      [normalize_name(name), manifest]
    end]
  end
  sources
end