Class: Bibliothecary::MultiParsers::CycloneDX::ManifestEntries
- Inherits:
-
Object
- Object
- Bibliothecary::MultiParsers::CycloneDX::ManifestEntries
- Defined in:
- lib/bibliothecary/multi_parsers/cyclonedx.rb
Instance Attribute Summary collapse
-
#manifests ⇒ Object
readonly
Returns the value of attribute manifests.
Instance Method Summary collapse
- #<<(purl) ⇒ Object
- #[](key) ⇒ Object
-
#initialize(parse_queue:) ⇒ ManifestEntries
constructor
A new instance of ManifestEntries.
-
#parse!(&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.
22 23 24 25 26 27 28 29 |
# File 'lib/bibliothecary/multi_parsers/cyclonedx.rb', line 22 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
#manifests ⇒ Object (readonly)
Returns the value of attribute manifests.
20 21 22 |
# File 'lib/bibliothecary/multi_parsers/cyclonedx.rb', line 20 def manifests @manifests end |
Instance Method Details
#<<(purl) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/bibliothecary/multi_parsers/cyclonedx.rb', line 31 def <<(purl) 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", ) end |
#[](key) ⇒ Object
60 61 62 |
# File 'lib/bibliothecary/multi_parsers/cyclonedx.rb', line 60 def [](key) @manifests[key]&.to_a end |
#parse!(&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.
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/bibliothecary/multi_parsers/cyclonedx.rb', line 46 def parse!(&block) while @parse_queue.length > 0 component = @parse_queue.shift purl_text = block.call(component, @parse_queue) next unless purl_text purl = PackageURL.parse(purl_text) self << purl end end |