forked from dependabot/dependabot-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.rb
81 lines (60 loc) · 2.74 KB
/
utils.rb
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# typed: strong
# frozen_string_literal: true
require "tmpdir"
require "set"
require "sorbet-runtime"
require "dependabot/requirement"
require "dependabot/version"
require "dependabot/config/file"
# TODO: in due course, these "registries" should live in a wrapper gem, not
# dependabot-core.
module Dependabot
module Utils
extend T::Sig
BUMP_TMP_FILE_PREFIX = "dependabot_"
BUMP_TMP_DIR_PATH = T.let(File.expand_path(Dir::Tmpname.create("", "tmp") { nil }), String)
@version_classes = T.let({}, T::Hash[String, T.class_of(Dependabot::Version)])
sig { params(package_manager: String).returns(T.class_of(Dependabot::Version)) }
def self.version_class_for_package_manager(package_manager)
version_class = @version_classes[package_manager]
return version_class if version_class
raise "Unregistered package_manager #{package_manager}"
end
sig { params(package_manager: String, version_class: T.class_of(Dependabot::Version)).void }
def self.register_version_class(package_manager, version_class)
validate_package_manager!(package_manager)
@version_classes[package_manager] = version_class
end
@requirement_classes = T.let({}, T::Hash[String, T.class_of(Dependabot::Requirement)])
sig { params(package_manager: String).returns(T.class_of(Dependabot::Requirement)) }
def self.requirement_class_for_package_manager(package_manager)
requirement_class = @requirement_classes[package_manager]
return requirement_class if requirement_class
raise "Unregistered package_manager #{package_manager}"
end
sig { params(package_manager: String, requirement_class: T.class_of(Dependabot::Requirement)).void }
def self.register_requirement_class(package_manager, requirement_class)
validate_package_manager!(package_manager)
@requirement_classes[package_manager] = requirement_class
end
@cloning_package_managers = T.let(Set[], T::Set[String])
sig { params(package_manager: String).returns(T::Boolean) }
def self.always_clone_for_package_manager?(package_manager)
@cloning_package_managers.include?(package_manager)
end
sig { params(package_manager: String).void }
def self.register_always_clone(package_manager)
validate_package_manager!(package_manager)
@cloning_package_managers << package_manager
end
sig { params(package_manager: String).void }
def self.validate_package_manager!(package_manager)
# Official package manager
return if Config::File::PACKAGE_MANAGER_LOOKUP.invert.key?(package_manager)
# Used by specs
return if package_manager == "dummy"
raise "Unsupported package_manager #{package_manager}"
end
private_class_method :validate_package_manager!
end
end