tap: various improvements (#77)

* make `read_or_set_private_config` private
* add doc
* add test
This commit is contained in:
Xu Cheng 2016-04-12 18:51:43 +08:00
parent f57739deda
commit 548be81b34
2 changed files with 35 additions and 21 deletions

View File

@ -145,32 +145,13 @@ class Tap
user == "Homebrew"
end
# @private
def read_and_set_private_config
case config["private"]
when "true" then true
when "false" then false
else
config["private"] = begin
if custom_remote?
true
else
GitHub.private_repo?(user, "homebrew-#{repo}")
end
rescue GitHub::HTTPNotFoundError
true
rescue GitHub::Error
false
end
end
end
# True if the remote of this {Tap} is a private repository.
def private?
return @private if instance_variable_defined?(:@private)
@private = read_and_set_private_config
@private = read_or_set_private_config
end
# {TapConfig} of this {Tap}
def config
@config ||= begin
raise TapUnavailableError, name unless installed?
@ -489,6 +470,28 @@ class Tap
def alias_file_to_name(file)
"#{name}/#{file.basename}"
end
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
GitHub.private_repo?(user, "homebrew-#{repo}")
end
rescue GitHub::HTTPNotFoundError
true
rescue GitHub::Error
false
end
end
end
end
# A specialized {Tap} class for the core formulae
@ -593,6 +596,7 @@ class CoreTap < Tap
end
end
# Permanent configuration per {Tap} using `git-config(1)`
class TapConfig
attr_reader :tap

View File

@ -231,6 +231,16 @@ class TapTest < Homebrew::TestCase
@tap.unpin
refute_predicate @tap, :pinned?
end
def test_config
setup_git_repo
assert_nil @tap.config["foo"]
@tap.config["foo"] = "bar"
assert_equal "bar", @tap.config["foo"]
@tap.config["foo"] = nil
assert_nil @tap.config["foo"]
end
end
class CoreTapTest < Homebrew::TestCase