Class: Bibliothecary::MultiParsers::CycloneDX::ManifestEntries
- Inherits:
-
Object
- Object
- Bibliothecary::MultiParsers::CycloneDX::ManifestEntries
- Defined in:
- lib/bibliothecary/multi_parsers/cyclonedx.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Instance Method Summary collapse
- #add(purl, source = nil) ⇒ Object
-
#initialize(parse_queue:) ⇒ ManifestEntries
constructor
A new instance of ManifestEntries.
-
#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.
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:) @entries = Set.new # 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
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
22 23 24 |
# File 'lib/bibliothecary/multi_parsers/cyclonedx.rb', line 22 def entries @entries end |
Instance Method Details
#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) # Use the mapped purl->bibliothecary platform, or else fall back to original platform itself. mapping = PurlUtil::PURL_TYPE_MAPPING.fetch(purl.type, purl.type) @entries << Dependency.new( name: PurlUtil.full_name(purl), requirement: purl.version, platform: mapping ? mapping.to_s : purl.type, 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 |