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, version = nil, 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, version = nil, 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, version = nil, 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: version || 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 and version.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/bibliothecary/multi_parsers/cyclonedx.rb', line 49 def parse!(source = nil, &block) until @parse_queue.empty? component = @parse_queue.shift result = block.call(component, @parse_queue) next unless result if result.is_a?(Hash) purl_text = result[:purl] version = result[:version] else purl_text = result version = nil end next unless purl_text purl = PackageURL.parse(purl_text) add(purl, version, source) end end |