Sha256: 89c6ac52fedb5c69f22dce7f2d34f6c58944e7d429f43cb400d847056daf34b2

Contents?: true

Size: 1.06 KB

Versions: 5

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module Spandx
  module Ruby
    class Index
      include Enumerable

      attr_reader :directory, :name, :rubygems

      def initialize(directory:)
        @directory = directory
        @name = 'rubygems'
        @cache = ::Spandx::Core::Cache.new(@name, root: directory)
        @rubygems = ::Spandx::Ruby::Gateway.new
      end

      def update!(*)
        queue = Queue.new
        [fetch(queue), save(queue)].each(&:join)
        cache.rebuild_index
      end

      private

      attr_reader :cache

      def fetch(queue)
        Thread.new do
          rubygems.each do |item|
            queue.enq(
              item.merge(
                licenses: rubygems.licenses(item[:name], item[:version])
              )
            )
          end
          queue.enq(:stop)
        end
      end

      def save(queue)
        Thread.new do
          loop do
            item = queue.deq
            break if item == :stop

            cache.insert(item[:name], item[:version], item[:licenses])
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spandx-0.18.3 lib/spandx/ruby/index.rb
spandx-0.18.2 lib/spandx/ruby/index.rb
spandx-0.18.1 lib/spandx/ruby/index.rb
spandx-0.18.0 lib/spandx/ruby/index.rb
spandx-0.17.0 lib/spandx/ruby/index.rb