Sha256: 63b99f917807d44637af3c62bc756b79098b2573962645ffdb50a5524dcaa5ce

Contents?: true

Size: 991 Bytes

Versions: 16

Compression:

Stored size: 991 Bytes

Contents

# frozen_string_literal: true

module Spandx
  module Python
    class Index
      include Enumerable

      attr_reader :directory, :name, :pypi, :source

      def initialize(directory:)
        @directory = directory
        @name = 'pypi'
        @source = 'https://pypi.org'
        @pypi = Pypi.new
        @cache = ::Spandx::Core::Cache.new(@name, root: directory)
      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
          pypi.each do |dependency|
            queue.enq(dependency)
          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[:license]])
          end
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
spandx-0.18.3 lib/spandx/python/index.rb
spandx-0.18.2 lib/spandx/python/index.rb
spandx-0.18.1 lib/spandx/python/index.rb
spandx-0.18.0 lib/spandx/python/index.rb
spandx-0.17.0 lib/spandx/python/index.rb
spandx-0.16.1 lib/spandx/python/index.rb
spandx-0.16.0 lib/spandx/python/index.rb
spandx-0.15.1 lib/spandx/python/index.rb
spandx-0.15.0 lib/spandx/python/index.rb
spandx-0.14.0 lib/spandx/python/index.rb
spandx-0.13.5 lib/spandx/python/index.rb
spandx-0.13.4 lib/spandx/python/index.rb
spandx-0.13.3 lib/spandx/python/index.rb
spandx-0.13.2 lib/spandx/python/index.rb
spandx-0.13.1 lib/spandx/python/index.rb
spandx-0.13.0 lib/spandx/python/index.rb