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.
This commit is contained in:
Xu Cheng 2015-05-08 13:48:36 +08:00
parent 6199da8fc7
commit 8297810e3c
5 changed files with 16 additions and 17 deletions

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)://]