tap: memoize allowed and forbidden taps

This commit is contained in:
Carlo Cabrera 2024-05-03 16:08:22 +01:00
parent 34e2c4ee97
commit 7c9e8927e9
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0

View File

@ -132,8 +132,11 @@ class Tap
false false
end end
# rubocop:disable Style/ClassVars
# We want the the class variables below to be global to all `Tap` classes and subclasses.
sig { returns(T::Set[Tap]) } sig { returns(T::Set[Tap]) }
def self.allowed_taps def self.allowed_taps
@@allowed_taps ||= begin
allowed_tap_list = Homebrew::EnvConfig.allowed_taps.to_s.split allowed_tap_list = Homebrew::EnvConfig.allowed_taps.to_s.split
Set.new(allowed_tap_list.filter_map do |tap| Set.new(allowed_tap_list.filter_map do |tap|
@ -144,8 +147,12 @@ class Tap
end) end)
end end
@@allowed_taps.freeze
end
sig { returns(T::Set[Tap]) } sig { returns(T::Set[Tap]) }
def self.forbidden_taps def self.forbidden_taps
@@forbidden_taps ||= begin
forbidden_tap_list = Homebrew::EnvConfig.forbidden_taps.to_s.split forbidden_tap_list = Homebrew::EnvConfig.forbidden_taps.to_s.split
Set.new(forbidden_tap_list.filter_map do |tap| Set.new(forbidden_tap_list.filter_map do |tap|
@ -156,6 +163,10 @@ class Tap
end) end)
end end
@@forbidden_taps.freeze
end
# rubocop:enable Style/ClassVars
# @api public # @api public
extend Enumerable extend Enumerable