diff options
| author | AnastasiaSulyagina | 2016-08-18 22:11:42 +0300 |
|---|---|---|
| committer | AnastasiaSulyagina | 2016-08-19 14:50:14 +0300 |
| commit | e81f4ab7deeb40308f240be5ea00091fc8786d7a (patch) | |
| tree | b5418f9149de71c0f05f90cb2b39ab47f46e27b4 /Library/Homebrew/cask/lib/hbc/source/tapped.rb | |
| parent | 5c7c9de669025bbe4cad9829be39c5cf3b31ad25 (diff) | |
| download | brew-e81f4ab7deeb40308f240be5ea00091fc8786d7a.tar.bz2 | |
init
Diffstat (limited to 'Library/Homebrew/cask/lib/hbc/source/tapped.rb')
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/source/tapped.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/source/tapped.rb b/Library/Homebrew/cask/lib/hbc/source/tapped.rb new file mode 100644 index 000000000..da9366840 --- /dev/null +++ b/Library/Homebrew/cask/lib/hbc/source/tapped.rb @@ -0,0 +1,35 @@ +class Hbc::Source::Tapped + def self.me?(query) + path_for_query(query).exist? + end + + 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 + + attr_reader :token + + def initialize(token) + @token = token + end + + def load + path = self.class.path_for_query(token) + Hbc::Source::PathSlashOptional.new(path).load + end + + def to_s + # stringify to fully-resolved location + self.class.path_for_query(token).expand_path.to_s + end +end |
