Only use HOMEBREW_TAP_PATH_REGEX once inside Tap class.

This commit is contained in:
Markus Reiter 2018-03-29 22:05:02 +02:00
parent db2cd52842
commit 94f2098c36
4 changed files with 8 additions and 9 deletions

View File

@ -97,14 +97,14 @@ module Hbc
class FromTapPathLoader < FromPathLoader class FromTapPathLoader < FromPathLoader
def self.can_load?(ref) def self.can_load?(ref)
File.expand_path(ref).match?(HOMEBREW_TAP_PATH_REGEX) && super super && !Tap.from_path(ref).nil?
end end
attr_reader :tap attr_reader :tap
def initialize(tap_path) def initialize(path)
@tap = Tap.from_path(File.expand_path(tap_path)) @tap = Tap.from_path(path)
super tap_path super(path)
end end
private private

View File

@ -181,8 +181,7 @@ class TapFormulaAmbiguityError < RuntimeError
@name = name @name = name
@paths = paths @paths = paths
@formulae = paths.map do |path| @formulae = paths.map do |path|
match = path.to_s.match(HOMEBREW_TAP_PATH_REGEX) "#{Tap.from_path(path).name}/#{path.basename(".rb")}"
"#{Tap.fetch(match[:user], match[:repo])}/#{path.basename(".rb")}"
end end
super <<~EOS super <<~EOS

View File

@ -179,8 +179,8 @@ class Formula
@tap = if path == Formulary.core_path(name) @tap = if path == Formulary.core_path(name)
CoreTap.instance CoreTap.instance
elsif match = path.to_s.match(HOMEBREW_TAP_PATH_REGEX) else
Tap.fetch(match[:user], match[:repo]) Tap.from_path(path)
end end
@full_name = full_name_with_optional_tap(name) @full_name = full_name_with_optional_tap(name)

View File

@ -39,7 +39,7 @@ class Tap
end end
def self.from_path(path) def self.from_path(path)
match = path.to_s.match(HOMEBREW_TAP_PATH_REGEX) match = File.expand_path(path).match(HOMEBREW_TAP_PATH_REGEX)
raise "Invalid tap path '#{path}'" unless match raise "Invalid tap path '#{path}'" unless match
fetch(match[:user], match[:repo]) fetch(match[:user], match[:repo])
rescue rescue