Tap: add from_path helper method.

This makes it easier to turn an arbitrary path into a tap path.
This commit is contained in:
Mike McQuaid 2017-03-18 16:56:59 +02:00
parent 1c10a6260f
commit ac10b2ab50

View File

@ -41,6 +41,15 @@ class Tap
CACHE.fetch(cache_key) { |key| CACHE[key] = Tap.new(user, repo) } CACHE.fetch(cache_key) { |key| CACHE[key] = Tap.new(user, repo) }
end end
def self.from_path(path)
path.to_s =~ HOMEBREW_TAP_PATH_REGEX
raise "Invalid tap path '#{path}'" unless $1
fetch($1, $2)
rescue
# No need to error as a nil tap is sufficient to show failure.
nil
end
extend Enumerable extend Enumerable
# The user name of this {Tap}. Usually, it's the Github username of # The user name of this {Tap}. Usually, it's the Github username of