tap: various improvements (#77)
* make `read_or_set_private_config` private * add doc * add test
This commit is contained in:
parent
f57739deda
commit
548be81b34
@ -145,32 +145,13 @@ class Tap
|
|||||||
user == "Homebrew"
|
user == "Homebrew"
|
||||||
end
|
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.
|
# True if the remote of this {Tap} is a private repository.
|
||||||
def private?
|
def private?
|
||||||
return @private if instance_variable_defined?(:@private)
|
return @private if instance_variable_defined?(:@private)
|
||||||
@private = read_and_set_private_config
|
@private = read_or_set_private_config
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# {TapConfig} of this {Tap}
|
||||||
def config
|
def config
|
||||||
@config ||= begin
|
@config ||= begin
|
||||||
raise TapUnavailableError, name unless installed?
|
raise TapUnavailableError, name unless installed?
|
||||||
@ -489,6 +470,28 @@ class Tap
|
|||||||
def alias_file_to_name(file)
|
def alias_file_to_name(file)
|
||||||
"#{name}/#{file.basename}"
|
"#{name}/#{file.basename}"
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
# A specialized {Tap} class for the core formulae
|
# A specialized {Tap} class for the core formulae
|
||||||
@ -593,6 +596,7 @@ class CoreTap < Tap
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Permanent configuration per {Tap} using `git-config(1)`
|
||||||
class TapConfig
|
class TapConfig
|
||||||
attr_reader :tap
|
attr_reader :tap
|
||||||
|
|
||||||
|
@ -231,6 +231,16 @@ class TapTest < Homebrew::TestCase
|
|||||||
@tap.unpin
|
@tap.unpin
|
||||||
refute_predicate @tap, :pinned?
|
refute_predicate @tap, :pinned?
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
class CoreTapTest < Homebrew::TestCase
|
class CoreTapTest < Homebrew::TestCase
|
||||||
|
Loading…
x
Reference in New Issue
Block a user