Class: Librarian::Lockfile::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/librarian/lockfile/parser.rb

Defined Under Namespace

Classes: ManifestPlaceholder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environment) ⇒ Parser

Returns a new instance of Parser.



19
20
21
# File 'lib/librarian/lockfile/parser.rb', line 19

def initialize(environment)
  self.environment = environment
end

Instance Attribute Details

#environmentObject

Returns the value of attribute environment.



16
17
18
# File 'lib/librarian/lockfile/parser.rb', line 16

def environment
  @environment
end

Instance Method Details

#parse(string) ⇒ Object

Raises:

  • (StandardError)


23
24
25
26
27
28
29
30
31
# File 'lib/librarian/lockfile/parser.rb', line 23

def parse(string)
  lines = string.lines.map{|l| l.sub(/\s+\z/, '')}.reject(&:empty?)
  sources = extract_and_parse_sources(lines)
  manifests = compile(sources)
  manifests_index = Hash[manifests.map{|m| [m.name, m]}]
  raise StandardError, "Expected DEPENDENCIES topic!" unless lines.shift == "DEPENDENCIES"
  dependencies = extract_and_parse_dependencies(lines, manifests_index)
  Resolution.new(dependencies, manifests)
end