2016-09-24 13:52:43 +02:00
|
|
|
module Hbc
|
|
|
|
module Source
|
|
|
|
class Tapped
|
|
|
|
def self.me?(query)
|
|
|
|
path_for_query(query).exist?
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def self.path_for_query(query)
|
|
|
|
# Repeating Hbc.all_tokens is very slow for operations such as
|
|
|
|
# brew cask list, but memoizing the value might cause breakage
|
|
|
|
# elsewhere, given that installation and tap status is permitted
|
|
|
|
# to change during the course of an invocation.
|
|
|
|
token_with_tap = Hbc.all_tokens.find { |t| t.split("/").last == query.sub(%r{\.rb$}i, "") }
|
|
|
|
if token_with_tap
|
|
|
|
user, repo, token = token_with_tap.split("/")
|
|
|
|
Tap.fetch(user, repo).cask_dir.join("#{token}.rb")
|
|
|
|
else
|
|
|
|
Hbc.default_tap.cask_dir.join(query.sub(%r{(\.rb)?$}i, ".rb"))
|
|
|
|
end
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
attr_reader :token
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def initialize(token)
|
|
|
|
@token = token
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def load
|
|
|
|
path = self.class.path_for_query(token)
|
|
|
|
PathSlashOptional.new(path).load
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def to_s
|
|
|
|
# stringify to fully-resolved location
|
|
|
|
self.class.path_for_query(token).expand_path.to_s
|
|
|
|
end
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|