Sha256: 91de8f9cf68551f77419a3d49b41270134d6af2150b50cdd391bfde6b979512a

Contents?: true

Size: 1.07 KB

Versions: 16

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module Spandx
  module Dotnet
    class Index
      DEFAULT_DIR = File.expand_path(File.join(Dir.home, '.local', 'share', 'spandx'))
      attr_reader :cache, :directory, :name, :gateway

      def initialize(directory: DEFAULT_DIR, gateway: Spandx::Dotnet::NugetGateway.new)
        @directory = directory ? File.expand_path(directory) : DEFAULT_DIR
        @name = 'nuget'
        @gateway = gateway
        @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

      def fetch(queue)
        Thread.new do
          gateway.each do |item|
            queue.enq(item)
          end
          queue.enq(:stop)
        end
      end

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

            cache.insert(item['id'], item['version'], [item['licenseExpression']])
          end
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

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