tap: avoid class vars
Avoiding them also allows us to write proper tests.
This commit is contained in:
parent
34387bfc8a
commit
078a328e8e
@ -132,11 +132,10 @@ 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
|
cache_key = "allowed_taps_#{Homebrew::EnvConfig.allowed_taps.to_s.gsub(" ", "_")}".to_sym
|
||||||
|
cache[cache_key] ||= 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,15 +143,14 @@ class Tap
|
|||||||
rescue Tap::InvalidNameError
|
rescue Tap::InvalidNameError
|
||||||
opoo "Invalid tap name in `HOMEBREW_ALLOWED_TAPS`: #{tap}"
|
opoo "Invalid tap name in `HOMEBREW_ALLOWED_TAPS`: #{tap}"
|
||||||
nil
|
nil
|
||||||
end)
|
end).freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
@@allowed_taps.freeze
|
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(T::Set[Tap]) }
|
sig { returns(T::Set[Tap]) }
|
||||||
def self.forbidden_taps
|
def self.forbidden_taps
|
||||||
@@forbidden_taps ||= begin
|
cache_key = "forbidden_taps_#{Homebrew::EnvConfig.forbidden_taps.to_s.gsub(" ", "_")}".to_sym
|
||||||
|
cache[cache_key] ||= 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|
|
||||||
@ -160,12 +158,9 @@ class Tap
|
|||||||
rescue Tap::InvalidNameError
|
rescue Tap::InvalidNameError
|
||||||
opoo "Invalid tap name in `HOMEBREW_FORBIDDEN_TAPS`: #{tap}"
|
opoo "Invalid tap name in `HOMEBREW_FORBIDDEN_TAPS`: #{tap}"
|
||||||
nil
|
nil
|
||||||
end)
|
end).freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
@@forbidden_taps.freeze
|
|
||||||
end
|
end
|
||||||
# rubocop:enable Style/ClassVars
|
|
||||||
|
|
||||||
# @api public
|
# @api public
|
||||||
extend Enumerable
|
extend Enumerable
|
||||||
|
@ -142,6 +142,24 @@ RSpec.describe Tap do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "::allowed_taps" do
|
||||||
|
before { allow(Homebrew::EnvConfig).to receive(:allowed_taps).and_return("homebrew/allowed") }
|
||||||
|
|
||||||
|
it "returns a set of allowed taps according to the environment" do
|
||||||
|
expect(described_class.allowed_taps)
|
||||||
|
.to contain_exactly(described_class.fetch("homebrew/allowed"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "::forbidden_taps" do
|
||||||
|
before { allow(Homebrew::EnvConfig).to receive(:forbidden_taps).and_return("homebrew/forbidden") }
|
||||||
|
|
||||||
|
it "returns a set of forbidden taps according to the environment" do
|
||||||
|
expect(described_class.forbidden_taps)
|
||||||
|
.to contain_exactly(described_class.fetch("homebrew/forbidden"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
specify "::names" do
|
specify "::names" do
|
||||||
expect(described_class.names.sort).to eq(["homebrew/core", "homebrew/foo"])
|
expect(described_class.names.sort).to eq(["homebrew/core", "homebrew/foo"])
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user