summaryrefslogtreecommitdiff
path: root/lib/spandx.rb
blob: 9bd81f5bf53cbfa28e6152f1fa3bded7a9ea3a8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# frozen_string_literal: true

require 'async'
require 'addressable/uri'
require 'bundler'
require 'csv'
require 'forwardable'
require 'json'
require 'logger'
require 'net/hippie'
require 'nokogiri'
require 'oj'
require 'parslet'
require 'pathname'
require 'yaml'
require 'zeitwerk'
require 'spandx/spandx'

loader = Zeitwerk::Loader.for_gem
loader.setup # ready!

module Spandx
  class Error < StandardError; end
  Rubygems = Ruby

  class << self
    attr_writer :airgap, :logger, :http, :git

    def root
      Pathname.new(File.dirname(__FILE__)).join('../..')
    end

    def airgap?
      @airgap
    end

    def http
      @http ||= Spandx::Core::Http.new
    end

    def logger
      @logger ||= Logger.new('/dev/null')
    end

    def git
      @git ||= {
        cache: ::Spandx::Core::Git.new(url: 'https://github.com/spandx/cache.git'),
        rubygems: ::Spandx::Core::Git.new(url: 'https://github.com/spandx/rubygems-cache.git'),
        spdx: ::Spandx::Core::Git.new(url: 'https://github.com/spdx/license-list-data.git'),
      }
    end
  end
end

loader.eager_load