aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorXu Cheng2015-05-08 13:48:36 +0800
committerXu Cheng2015-05-08 13:51:26 +0800
commit8297810e3c4d5a15cb9b176f5a02a6023a6db7be (patch)
treef0235d34b40cbfb5bce6074753d63ebc65aeed8d /Library
parent6199da8fc73c2b36d69a41771612b25db27c88ed (diff)
downloadbrew-8297810e3c4d5a15cb9b176f5a02a6023a6db7be.tar.bz2
add Formulary::path method
This is a little code refactoring splited from Homebrew/homebrew#36753 The idea is to eliminate `Formula#path` outside of `formulary.rb`. And I indent to deprecate `Formula#path` method when I reimplement symlink free tap function. Closes Homebrew/homebrew#39313.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cmd/create.rb6
-rw-r--r--Library/Homebrew/cmd/edit.rb10
-rw-r--r--Library/Homebrew/cmd/log.rb9
-rw-r--r--Library/Homebrew/cmd/readall.rb2
-rw-r--r--Library/Homebrew/formulary.rb6
5 files changed, 16 insertions, 17 deletions
diff --git a/Library/Homebrew/cmd/create.rb b/Library/Homebrew/cmd/create.rb
index b9bc9cd13..11c51d598 100644
--- a/Library/Homebrew/cmd/create.rb
+++ b/Library/Homebrew/cmd/create.rb
@@ -40,7 +40,7 @@ module Homebrew
stem = Pathname.new(url).stem
print "Formula name [#{stem}]: "
fc.name = __gets || stem
- fc.path = Formula.path(fc.name)
+ fc.path = Formulary.path(fc.name)
end
# Don't allow blacklisted formula, or names that shadow aliases,
@@ -84,9 +84,9 @@ class FormulaCreator
@name ||= $1
/(.*?)[-_.]?#{path.version}/.match path.basename
@name ||= $1
- @path = Formula.path @name unless @name.nil?
+ @path = Formulary.path @name unless @name.nil?
else
- @path = Formula.path name
+ @path = Formulary.path name
end
if @version
@version = Version.new(@version)
diff --git a/Library/Homebrew/cmd/edit.rb b/Library/Homebrew/cmd/edit.rb
index c4f137ea4..534fcba33 100644
--- a/Library/Homebrew/cmd/edit.rb
+++ b/Library/Homebrew/cmd/edit.rb
@@ -26,13 +26,11 @@ module Homebrew
else
# Don't use ARGV.formulae as that will throw if the file doesn't parse
paths = ARGV.named.map do |name|
- name = Formulary.canonical_name(name)
- Formula.path(name)
- end
- unless ARGV.force?
- paths.each do |path|
- raise FormulaUnavailableError, path.basename('.rb').to_s unless path.file?
+ path = Formulary.path(name)
+ unless path.file? || ARGV.force?
+ raise FormulaUnavailableError, name
end
+ path
end
exec_editor(*paths)
end
diff --git a/Library/Homebrew/cmd/log.rb b/Library/Homebrew/cmd/log.rb
index c45f4735c..6ffeab1e4 100644
--- a/Library/Homebrew/cmd/log.rb
+++ b/Library/Homebrew/cmd/log.rb
@@ -1,15 +1,12 @@
+require "formula"
+
module Homebrew
def log
if ARGV.named.empty?
cd HOMEBREW_REPOSITORY
exec "git", "log", *ARGV.options_only
else
- begin
- path = ARGV.formulae.first.path
- rescue FormulaUnavailableError
- # Maybe the formula was deleted
- path = Formula.path(ARGV.named.first)
- end
+ path = Formulary.path(ARGV.named.first)
cd path.dirname # supports taps
exec "git", "log", *ARGV.options_only + ["--", path]
end
diff --git a/Library/Homebrew/cmd/readall.rb b/Library/Homebrew/cmd/readall.rb
index 513a9b7c2..ce5be80a8 100644
--- a/Library/Homebrew/cmd/readall.rb
+++ b/Library/Homebrew/cmd/readall.rb
@@ -46,7 +46,7 @@ module Homebrew
begin
Formulary.factory(n)
rescue Exception => e
- onoe "problem in #{Formula.path(n)}"
+ onoe "problem in #{Formulary.path(n)}"
puts e
Homebrew.failed = true
end
diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb
index 3815105c2..24c2788a7 100644
--- a/Library/Homebrew/formulary.rb
+++ b/Library/Homebrew/formulary.rb
@@ -182,7 +182,7 @@ class Formulary
class NullLoader < FormulaLoader
def initialize(name)
- @name = name
+ super name, Formula.path(name)
end
def get_formula(spec)
@@ -204,6 +204,10 @@ class Formulary
loader_for(ref).name
end
+ def self.path(ref)
+ loader_for(ref).path
+ end
+
def self.loader_for(ref)
case ref
when %r[(https?|ftp)://]