Simplify TapConfig.
This commit is contained in:
parent
8a852cf8c8
commit
be9c0b8787
@ -274,11 +274,29 @@ class Tap
|
||||
user == "Homebrew"
|
||||
end
|
||||
|
||||
# True if the remote of this {Tap} is a private repository.
|
||||
# Check whether the remote of this {Tap} is a private repository.
|
||||
sig { returns(T::Boolean) }
|
||||
def private?
|
||||
return @private if instance_variable_defined?(:@private)
|
||||
return @private if defined?(@private)
|
||||
|
||||
@private = read_or_set_private_config
|
||||
@private = if (value = config[:private]).nil?
|
||||
config[:private] = begin
|
||||
if custom_remote?
|
||||
true
|
||||
else
|
||||
# Don't store config if we don't know for sure.
|
||||
return false if (value = GitHub.private_repo?(full_name)).nil?
|
||||
|
||||
value
|
||||
end
|
||||
rescue GitHub::API::HTTPNotFoundError
|
||||
true
|
||||
rescue GitHub::API::Error
|
||||
false
|
||||
end
|
||||
else
|
||||
value
|
||||
end
|
||||
end
|
||||
|
||||
# {TapConfig} of this {Tap}.
|
||||
@ -292,6 +310,7 @@ class Tap
|
||||
end
|
||||
|
||||
# True if this {Tap} has been installed.
|
||||
sig { returns(T::Boolean) }
|
||||
def installed?
|
||||
path.directory?
|
||||
end
|
||||
@ -351,12 +370,12 @@ class Tap
|
||||
fix_remote_configuration(requested_remote: requested_remote, quiet: quiet)
|
||||
end
|
||||
|
||||
unless force_auto_update.nil?
|
||||
if force_auto_update
|
||||
config["forceautoupdate"] = force_auto_update
|
||||
elsif config["forceautoupdate"] == "true"
|
||||
config.delete("forceautoupdate")
|
||||
end
|
||||
case force_auto_update
|
||||
when true
|
||||
config[:forceautoupdate] = true
|
||||
return
|
||||
when false
|
||||
config.delete(:forceautoupdate)
|
||||
return
|
||||
end
|
||||
|
||||
@ -403,7 +422,7 @@ class Tap
|
||||
raise
|
||||
end
|
||||
|
||||
config["forceautoupdate"] = force_auto_update unless force_auto_update.nil?
|
||||
config[:forceautoupdate] = force_auto_update unless force_auto_update.nil?
|
||||
|
||||
Commands.rebuild_commands_completion_list
|
||||
link_completions_and_manpages
|
||||
@ -976,28 +995,6 @@ class Tap
|
||||
|
||||
private
|
||||
|
||||
def read_or_set_private_config
|
||||
case config["private"]
|
||||
when "true" then true
|
||||
when "false" then false
|
||||
else
|
||||
config["private"] = begin
|
||||
if custom_remote?
|
||||
true
|
||||
else
|
||||
# Don't store config if we don't know for sure.
|
||||
return false if (value = GitHub.private_repo?(full_name)).nil?
|
||||
|
||||
value
|
||||
end
|
||||
rescue GitHub::API::HTTPNotFoundError
|
||||
true
|
||||
rescue GitHub::API::Error
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
sig { params(file: Pathname).returns(T.any(T::Array[String], Hash)) }
|
||||
def read_formula_list(file)
|
||||
JSON.parse file.read
|
||||
@ -1375,15 +1372,18 @@ class TapConfig
|
||||
@tap = tap
|
||||
end
|
||||
|
||||
sig { params(key: T.any(Symbol, String)).returns(T.nilable(String)) }
|
||||
sig { params(key: Symbol).returns(T.nilable(T::Boolean)) }
|
||||
def [](key)
|
||||
return unless tap.git?
|
||||
return unless Utils::Git.available?
|
||||
|
||||
Homebrew::Settings.read key, repo: tap.path
|
||||
case Homebrew::Settings.read(key, repo: tap.path)
|
||||
when "true" then true
|
||||
when "false" then false
|
||||
end
|
||||
end
|
||||
|
||||
sig { params(key: T.any(Symbol, String), value: T.any(T::Boolean, String)).void }
|
||||
sig { params(key: Symbol, value: T::Boolean).void }
|
||||
def []=(key, value)
|
||||
return unless tap.git?
|
||||
return unless Utils::Git.available?
|
||||
@ -1391,7 +1391,7 @@ class TapConfig
|
||||
Homebrew::Settings.write key, value.to_s, repo: tap.path
|
||||
end
|
||||
|
||||
sig { params(key: T.any(Symbol, String)).void }
|
||||
sig { params(key: Symbol).void }
|
||||
def delete(key)
|
||||
return unless tap.git?
|
||||
return unless Utils::Git.available?
|
||||
|
||||
@ -363,19 +363,19 @@ RSpec.describe Tap do
|
||||
|
||||
it "defaults to nil" do
|
||||
expect(already_tapped_tap).to be_installed
|
||||
expect(already_tapped_tap.config["forceautoupdate"]).to be_nil
|
||||
expect(already_tapped_tap.config[:forceautoupdate]).to be_nil
|
||||
end
|
||||
|
||||
it "enables forced auto-updates when true" do
|
||||
expect(already_tapped_tap).to be_installed
|
||||
already_tapped_tap.install force_auto_update: true
|
||||
expect(already_tapped_tap.config["forceautoupdate"]).to eq("true")
|
||||
expect(already_tapped_tap.config[:forceautoupdate]).to be true
|
||||
end
|
||||
|
||||
it "disables forced auto-updates when false" do
|
||||
expect(already_tapped_tap).to be_installed
|
||||
already_tapped_tap.install force_auto_update: false
|
||||
expect(already_tapped_tap.config["forceautoupdate"]).to be_nil
|
||||
expect(already_tapped_tap.config[:forceautoupdate]).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
@ -488,11 +488,11 @@ RSpec.describe Tap do
|
||||
specify "#config" do
|
||||
setup_git_repo
|
||||
|
||||
expect(homebrew_foo_tap.config["foo"]).to be_nil
|
||||
homebrew_foo_tap.config["foo"] = "bar"
|
||||
expect(homebrew_foo_tap.config["foo"]).to eq("bar")
|
||||
homebrew_foo_tap.config.delete("foo")
|
||||
expect(homebrew_foo_tap.config["foo"]).to be_nil
|
||||
expect(homebrew_foo_tap.config[:foo]).to be_nil
|
||||
homebrew_foo_tap.config[:foo] = true
|
||||
expect(homebrew_foo_tap.config[:foo]).to be true
|
||||
homebrew_foo_tap.config.delete(:foo)
|
||||
expect(homebrew_foo_tap.config[:foo]).to be_nil
|
||||
end
|
||||
|
||||
describe "#each" do
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user