aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorXu Cheng2015-10-07 17:54:20 +0800
committerXu Cheng2015-10-14 17:26:41 +0800
commit98633e03c62bdf9f658338f57895da788c9eb76c (patch)
tree170b32a16d940bcffeb9e8d41f46f0223a262b23 /Library
parent65488903f9a10a8b5bbf39a13eaf9a40a789ca5b (diff)
downloadbrew-98633e03c62bdf9f658338f57895da788c9eb76c.tar.bz2
add alias_table and alias_reverse_table for core and tap
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/formula.rb23
-rw-r--r--Library/Homebrew/tap.rb23
2 files changed, 46 insertions, 0 deletions
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index fb274533e..8f0e0e141 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -1052,6 +1052,29 @@ class Formula
@alias_full_names ||= core_aliases + tap_aliases
end
+ # a table mapping core alias to formula name
+ # @private
+ def self.core_alias_table
+ return @core_alias_table if @core_alias_table
+ @core_alias_table = Hash.new
+ core_alias_files.each do |alias_file|
+ @core_alias_table[alias_file.basename.to_s] = alias_file.resolved_path.basename(".rb").to_s
+ end
+ @core_alias_table
+ end
+
+ # a table mapping core formula name to aliases
+ # @private
+ def self.core_alias_reverse_table
+ return @core_alias_reverse_table if @core_alias_reverse_table
+ @core_alias_reverse_table = Hash.new
+ core_alias_table.each do |alias_name, formula_name|
+ @core_alias_reverse_table[formula_name] ||= []
+ @core_alias_reverse_table[formula_name] << alias_name
+ end
+ @core_alias_reverse_table
+ end
+
def self.[](name)
Formulary.factory(name)
end
diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb
index 0313de8e8..f97383634 100644
--- a/Library/Homebrew/tap.rb
+++ b/Library/Homebrew/tap.rb
@@ -121,6 +121,29 @@ class Tap
@aliases ||= alias_files.map { |f| "#{name}/#{f.basename}" }
end
+ # a table mapping alias to formula name
+ # @private
+ def alias_table
+ return @alias_table if @alias_table
+ @alias_table = Hash.new
+ alias_files.each do |alias_file|
+ @alias_table["#{name}/#{alias_file.basename}"] = "#{name}/#{alias_file.resolved_path.basename(".rb")}"
+ end
+ @alias_table
+ end
+
+ # a table mapping formula name to aliases
+ # @private
+ def alias_reverse_table
+ return @alias_reverse_table if @alias_reverse_table
+ @alias_reverse_table = Hash.new
+ alias_table.each do |alias_name, formula_name|
+ @alias_reverse_table[formula_name] ||= []
+ @alias_reverse_table[formula_name] << alias_name
+ end
+ @alias_reverse_table
+ end
+
# an array of all commands files of this {Tap}.
def command_files
@command_files ||= Pathname.glob("#{path}/cmd/brew-*").select(&:executable?)