Remove TapDependency

This commit is contained in:
Bo Anderson 2023-06-19 04:37:55 +01:00
parent fd4f488072
commit 53d513695a
No known key found for this signature in database
GPG Key ID: 3DB94E204E137D65
4 changed files with 19 additions and 34 deletions

View File

@ -56,11 +56,7 @@ module DependenciesHelpers
# If a tap isn't installed, we can't find the dependencies of one of
# its formulae, and an exception will be thrown if we try.
if klass == Dependency &&
dep.is_a?(TapDependency) &&
!dep.tap.installed?
Dependency.keep_but_prune_recursive_deps
end
Dependency.keep_but_prune_recursive_deps if klass == Dependency && dep.tap && !dep.tap.installed?
end
end

View File

@ -11,18 +11,20 @@ class Dependency
include Dependable
extend Cachable
attr_reader :name, :env_proc, :option_names
attr_reader :name, :env_proc, :option_names, :tap
DEFAULT_ENV_PROC = proc {}.freeze
private_constant :DEFAULT_ENV_PROC
def initialize(name, tags = [], env_proc = DEFAULT_ENV_PROC, option_names = [name])
def initialize(name, tags = [], env_proc = DEFAULT_ENV_PROC, option_names = [name&.split("/")&.last])
raise ArgumentError, "Dependency must have a name!" unless name
@name = name
@tags = tags
@env_proc = env_proc
@option_names = option_names
@tap = Tap.fetch(Regexp.last_match(1), Regexp.last_match(2)) if name =~ HOMEBREW_TAP_FORMULA_REGEX
end
def to_s
@ -46,6 +48,8 @@ class Dependency
def installed?
to_formula.latest_version_installed?
rescue FormulaUnavailableError
false
end
def satisfied?(inherited_options = [])
@ -204,19 +208,3 @@ class Dependency
end
end
end
# A dependency on another Homebrew formula in a specific tap.
class TapDependency < Dependency
attr_reader :tap
def initialize(name, tags = [], env_proc = DEFAULT_ENV_PROC, option_names = [name.split("/").last])
@tap = Tap.fetch(name.rpartition("/").first)
super(name, tags, env_proc, option_names)
end
def installed?
super
rescue FormulaUnavailableError
false
end
end

View File

@ -144,12 +144,8 @@ class DependencyCollector
end
def parse_string_spec(spec, tags)
if spec.match?(HOMEBREW_TAP_FORMULA_REGEX)
TapDependency.new(spec, tags)
else
Dependency.new(spec, tags)
end
end
def parse_symbol_spec(spec, tags)
# When modifying this list of supported requirements, consider

View File

@ -100,15 +100,20 @@ describe Dependency do
expect(foo1).not_to eql(foo3)
end
describe TapDependency do
subject(:dependency) { described_class.new("foo/bar/dog") }
specify "#tap" do
describe "#tap" do
it "returns a tap passed a fully-qualified name" do
dependency = described_class.new("foo/bar/dog")
expect(dependency.tap).to eq(Tap.new("foo", "bar"))
end
it "returns no tap passed a simple name" do
dependency = described_class.new("dog")
expect(dependency.tap).to be_nil
end
end
specify "#option_names" do
dependency = described_class.new("foo/bar/dog")
expect(dependency.option_names).to eq(%w[dog])
end
end
end