diff options
| author | Markus Reiter | 2016-10-08 13:25:38 +0200 |
|---|---|---|
| committer | Markus Reiter | 2016-10-09 15:34:12 +0200 |
| commit | 67a7d1a64a0d69d60a6cdd17a8296c8cce215b7f (patch) | |
| tree | 61dff51ef579ff79a5df332fd5eeb644afd46002 /Library/Homebrew/cask/lib/hbc/source | |
| parent | 0c193c308ecfac9a6c9dba514a9d3991f8c6cecf (diff) | |
| download | brew-67a7d1a64a0d69d60a6cdd17a8296c8cce215b7f.tar.bz2 | |
Fix getting cask path for queries.
Diffstat (limited to 'Library/Homebrew/cask/lib/hbc/source')
4 files changed, 10 insertions, 74 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/source/path_base.rb b/Library/Homebrew/cask/lib/hbc/source/path_base.rb index 5725380ec..7d68e518b 100644 --- a/Library/Homebrew/cask/lib/hbc/source/path_base.rb +++ b/Library/Homebrew/cask/lib/hbc/source/path_base.rb @@ -1,4 +1,5 @@ require "rubygems" +require "hbc/cask_loader" module Hbc module Source @@ -6,67 +7,22 @@ module Hbc # derived classes must define method self.me? def self.path_for_query(query) - query_string = query.to_s - Pathname.new(query_string.end_with?(".rb") ? query_string : query_string + ".rb") + Pathname.new(query).sub(%r{(\.rb)?$}, ".rb") end attr_reader :path def initialize(path) - @path = Pathname(path).expand_path + @path = Pathname.new(path).expand_path end def load - raise CaskError, "File '#{path}' does not exist" unless path.exist? - raise CaskError, "File '#{path}' is not readable" unless path.readable? - raise CaskError, "File '#{path}' is not a plain file" unless path.file? - load_cask + CaskLoader.load_from_file(@path) end def to_s # stringify to fully-resolved location - path.to_s - end - - private - - def load_cask - instance_eval(cask_contents, __FILE__, __LINE__) - rescue CaskError, StandardError, ScriptError => e - # bug: e.message.concat doesn't work with CaskError exceptions - raise e, e.message.concat(" while loading '#{path}'") - end - - def cask_contents - File.open(path, "rb") do |handle| - contents = handle.read - if defined?(Encoding) - contents.force_encoding("UTF-8") - else - contents - end - end - end - - def cask(header_token, &block) - build_cask(Cask, header_token, &block) - end - - def test_cask(header_token, &block) - build_cask(TestCask, header_token, &block) - end - - def build_cask(cask_class, header_token, &block) - if header_token.is_a?(Hash) - # Cask file is using old `cask :v1 => 'token'` syntax - header_token = header_token.values.first - end - raise CaskTokenDoesNotMatchError.new(cask_token, header_token) unless cask_token == header_token - cask_class.new(cask_token, sourcefile_path: path, &block) - end - - def cask_token - path.basename.to_s.sub(%r{\.rb}, "") + @path.to_s end end end diff --git a/Library/Homebrew/cask/lib/hbc/source/tapped.rb b/Library/Homebrew/cask/lib/hbc/source/tapped.rb index 6716e3a35..c1f5f95bc 100644 --- a/Library/Homebrew/cask/lib/hbc/source/tapped.rb +++ b/Library/Homebrew/cask/lib/hbc/source/tapped.rb @@ -2,21 +2,7 @@ module Hbc module Source class 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 + Hbc.path(query).exist? end attr_reader :token @@ -26,13 +12,12 @@ module Hbc end def load - path = self.class.path_for_query(token) - PathSlashOptional.new(path).load + PathSlashOptional.new(Hbc.path(token)).load end def to_s # stringify to fully-resolved location - self.class.path_for_query(token).expand_path.to_s + Hbc.path(token).expand_path.to_s end end end diff --git a/Library/Homebrew/cask/lib/hbc/source/tapped_qualified.rb b/Library/Homebrew/cask/lib/hbc/source/tapped_qualified.rb index 52191f279..2db6ddbca 100644 --- a/Library/Homebrew/cask/lib/hbc/source/tapped_qualified.rb +++ b/Library/Homebrew/cask/lib/hbc/source/tapped_qualified.rb @@ -6,7 +6,7 @@ module Hbc def self.me?(query) return if (tap = tap_for_query(query)).nil? - tap.installed? && path_for_query(query).exist? + tap.installed? && Hbc.path(query).exist? end def self.tap_for_query(query) @@ -16,11 +16,6 @@ module Hbc user, repo = qualified_token[0..1] Tap.fetch(user, repo) end - - def self.path_for_query(query) - user, repo, token = QualifiedToken.parse(query) - Tap.fetch(user, repo).cask_dir.join(token.sub(%r{(\.rb)?$}i, ".rb")) - end end end end diff --git a/Library/Homebrew/cask/lib/hbc/source/untapped_qualified.rb b/Library/Homebrew/cask/lib/hbc/source/untapped_qualified.rb index 6041605d8..698cc46ce 100644 --- a/Library/Homebrew/cask/lib/hbc/source/untapped_qualified.rb +++ b/Library/Homebrew/cask/lib/hbc/source/untapped_qualified.rb @@ -7,7 +7,7 @@ module Hbc return if (tap = tap_for_query(query)).nil? tap.install - tap.installed? && path_for_query(query).exist? + tap.installed? && Hbc.path(query).exist? end end end |
