Class: Librarian::Lockfile::Parser
- Inherits:
-
Object
- Object
- Librarian::Lockfile::Parser
- Includes:
- Puppet::Util
- Defined in:
- lib/librarian/puppet/lockfile/parser.rb
Instance Method Summary collapse
Methods included from Puppet::Util
#clean_uri, #cp_r, #debug, #info, #normalize_name, #organization_name, #warn
Instance Method Details
#parse(string) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/librarian/puppet/lockfile/parser.rb', line 10 def parse(string) string = string.dup source_type_names_map = Hash[dsl_class.source_types.map{|t| [t[1].lock_name, t[1]]}] source_type_names = dsl_class.source_types.map{|t| t[1].lock_name} lines = string.split(/(\r|\n|\r\n)+/).select{|l| l =~ /\S/} sources = [] while source_type_names.include?(lines.first) source = {} source_type_name = lines.shift source[:type] = source_type_names_map[source_type_name] = {} while lines.first =~ /^ {2}([\w\-\/]+):\s+(.+)$/ lines.shift [$1.to_sym] = $2 end source[:options] = lines.shift # specs manifests = {} while lines.first =~ /^ {4}([\w\-\/]+) \((.*)\)$/ # This change allows forward slash lines.shift name, version = normalize_name($1), $2 manifests[name] = {:version => version, :dependencies => {}} while lines.first =~ /^ {6}([\w\-\/]+) \((.*)\)$/ lines.shift manifests[name][:dependencies][$1] = $2.split(/,\s*/) end end source[:manifests] = manifests sources << source end manifests = compile(sources) manifests_index = Hash[manifests.map{|m| [m.name, m]}] raise StandardError, "Expected DEPENDENCIES topic!" unless lines.shift == "DEPENDENCIES" dependencies = [] while lines.first =~ /^ {2}([\w\-\/]+)(?: \((.*)\))?$/ # This change allows forward slash lines.shift name, requirement = normalize_name($1), $2.split(/,\s*/) dependencies << Dependency.new(name, requirement, manifests_index[name].source) end Resolution.new(dependencies, manifests) end |