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:
parent
6199da8fc7
commit
8297810e3c
@ -40,7 +40,7 @@ module Homebrew
|
|||||||
stem = Pathname.new(url).stem
|
stem = Pathname.new(url).stem
|
||||||
print "Formula name [#{stem}]: "
|
print "Formula name [#{stem}]: "
|
||||||
fc.name = __gets || stem
|
fc.name = __gets || stem
|
||||||
fc.path = Formula.path(fc.name)
|
fc.path = Formulary.path(fc.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Don't allow blacklisted formula, or names that shadow aliases,
|
# Don't allow blacklisted formula, or names that shadow aliases,
|
||||||
@ -84,9 +84,9 @@ class FormulaCreator
|
|||||||
@name ||= $1
|
@name ||= $1
|
||||||
/(.*?)[-_.]?#{path.version}/.match path.basename
|
/(.*?)[-_.]?#{path.version}/.match path.basename
|
||||||
@name ||= $1
|
@name ||= $1
|
||||||
@path = Formula.path @name unless @name.nil?
|
@path = Formulary.path @name unless @name.nil?
|
||||||
else
|
else
|
||||||
@path = Formula.path name
|
@path = Formulary.path name
|
||||||
end
|
end
|
||||||
if @version
|
if @version
|
||||||
@version = Version.new(@version)
|
@version = Version.new(@version)
|
||||||
|
|||||||
@ -26,13 +26,11 @@ module Homebrew
|
|||||||
else
|
else
|
||||||
# Don't use ARGV.formulae as that will throw if the file doesn't parse
|
# Don't use ARGV.formulae as that will throw if the file doesn't parse
|
||||||
paths = ARGV.named.map do |name|
|
paths = ARGV.named.map do |name|
|
||||||
name = Formulary.canonical_name(name)
|
path = Formulary.path(name)
|
||||||
Formula.path(name)
|
unless path.file? || ARGV.force?
|
||||||
end
|
raise FormulaUnavailableError, name
|
||||||
unless ARGV.force?
|
|
||||||
paths.each do |path|
|
|
||||||
raise FormulaUnavailableError, path.basename('.rb').to_s unless path.file?
|
|
||||||
end
|
end
|
||||||
|
path
|
||||||
end
|
end
|
||||||
exec_editor(*paths)
|
exec_editor(*paths)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,15 +1,12 @@
|
|||||||
|
require "formula"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
def log
|
def log
|
||||||
if ARGV.named.empty?
|
if ARGV.named.empty?
|
||||||
cd HOMEBREW_REPOSITORY
|
cd HOMEBREW_REPOSITORY
|
||||||
exec "git", "log", *ARGV.options_only
|
exec "git", "log", *ARGV.options_only
|
||||||
else
|
else
|
||||||
begin
|
path = Formulary.path(ARGV.named.first)
|
||||||
path = ARGV.formulae.first.path
|
|
||||||
rescue FormulaUnavailableError
|
|
||||||
# Maybe the formula was deleted
|
|
||||||
path = Formula.path(ARGV.named.first)
|
|
||||||
end
|
|
||||||
cd path.dirname # supports taps
|
cd path.dirname # supports taps
|
||||||
exec "git", "log", *ARGV.options_only + ["--", path]
|
exec "git", "log", *ARGV.options_only + ["--", path]
|
||||||
end
|
end
|
||||||
|
|||||||
@ -46,7 +46,7 @@ module Homebrew
|
|||||||
begin
|
begin
|
||||||
Formulary.factory(n)
|
Formulary.factory(n)
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
onoe "problem in #{Formula.path(n)}"
|
onoe "problem in #{Formulary.path(n)}"
|
||||||
puts e
|
puts e
|
||||||
Homebrew.failed = true
|
Homebrew.failed = true
|
||||||
end
|
end
|
||||||
|
|||||||
@ -182,7 +182,7 @@ class Formulary
|
|||||||
|
|
||||||
class NullLoader < FormulaLoader
|
class NullLoader < FormulaLoader
|
||||||
def initialize(name)
|
def initialize(name)
|
||||||
@name = name
|
super name, Formula.path(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_formula(spec)
|
def get_formula(spec)
|
||||||
@ -204,6 +204,10 @@ class Formulary
|
|||||||
loader_for(ref).name
|
loader_for(ref).name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.path(ref)
|
||||||
|
loader_for(ref).path
|
||||||
|
end
|
||||||
|
|
||||||
def self.loader_for(ref)
|
def self.loader_for(ref)
|
||||||
case ref
|
case ref
|
||||||
when %r[(https?|ftp)://]
|
when %r[(https?|ftp)://]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user