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