Sha256: b3c9d634c644b3de71aac1e6cb18356302f8795a89db59b02af108371ba3fdc3

Contents?: true

Size: 885 Bytes

Versions: 5

Compression:

Stored size: 885 Bytes

Contents

# frozen_string_literal: true

module Spandx
  module Core
    class Parser
      UNKNOWN = Class.new do
        def self.parse(*_args)
          []
        end
      end

      attr_reader :catalogue

      def initialize(catalogue:)
        @catalogue = catalogue
      end

      class << self
        include Enumerable

        def each(&block)
          registry.each do |x|
            block.call(x)
          end
        end

        def inherited(subclass)
          registry.push(subclass)
        end

        def registry
          @registry ||= []
        end

        def for(path, catalogue: Spandx::Spdx::Catalogue.from_git)
          Spandx.logger.debug(path)
          result = ::Spandx::Core::Parser.find do |x|
            x.matches?(File.basename(path))
          end

          result&.new(catalogue: catalogue) || UNKNOWN
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spandx-0.11.0 lib/spandx/core/parser.rb
spandx-0.10.1 lib/spandx/core/parser.rb
spandx-0.10.0 lib/spandx/core/parser.rb
spandx-0.9.0 lib/spandx/core/parser.rb
spandx-0.8.0 lib/spandx/core/parser.rb