Class: Bibliothecary::MultiParsers::CycloneDX::ManifestEntries

Inherits:
Object
  • Object
show all
Defined in:
lib/bibliothecary/multi_parsers/cyclonedx.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parse_queue:) ⇒ ManifestEntries

Returns a new instance of ManifestEntries.



24
25
26
27
28
29
30
31
# File 'lib/bibliothecary/multi_parsers/cyclonedx.rb', line 24

def initialize(parse_queue:)
  @manifests = {}

  # Instead of recursing, we'll work through a queue of components
  # to process, letting the different parser add components to the
  # queue however they need to  pull them from the source document.
  @parse_queue = parse_queue.dup
end

Instance Attribute Details

#manifestsObject (readonly)

Returns the value of attribute manifests.



22
23
24
# File 'lib/bibliothecary/multi_parsers/cyclonedx.rb', line 22

def manifests
  @manifests
end

Instance Method Details

#[](key) ⇒ Object



63
64
65
# File 'lib/bibliothecary/multi_parsers/cyclonedx.rb', line 63

def [](key)
  @manifests[key]&.to_a
end

#add(purl, source = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/bibliothecary/multi_parsers/cyclonedx.rb', line 33

def add(purl, source = nil)
  mapping = PurlUtil::PURL_TYPE_MAPPING[purl.type]
  return unless mapping

  @manifests[mapping] ||= Set.new
  @manifests[mapping] << Dependency.new(
    name: PurlUtil.full_name(purl),
    requirement: purl.version,
    type: "lockfile",
    source: source
  )
end

#parse!(source = nil, &block) ⇒ Object

Iterates over each manifest entry in the parse_queue, and accepts a block which will be called on each component. The block has two jobs: 1) add more sub-components to parse (if they exist), and 2) return the components purl.



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/bibliothecary/multi_parsers/cyclonedx.rb', line 49

def parse!(source = nil, &block)
  until @parse_queue.empty?
    component = @parse_queue.shift

    purl_text = block.call(component, @parse_queue)

    next unless purl_text

    purl = PackageURL.parse(purl_text)

    add(purl, source)
  end
end