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.
ClosesHomebrew/homebrew#39313.
Formulary.loader_for cannot raise exceptions, as canonical_name must
work for nonexistent formulae. However, we can skip the constant lookup
and a redundant file existence check by returning a loader that raises
immediately in #get_formula.
This clause originated in 4a36c56ac7b36904712aa472b9bd50ef1b0c80d3,
attempting to catch NameErrors raised by const_defined? calls earlier in
the method body. Those const_defined? calls have since been moved out of
the body of the begin block.
Stop rescuing NameError here, which will make true programming errors in
formulae easier to debug.
`brew install ./foo` treats `./foo` like `./foo.rb`. This requires
a confusing special case in the name resolution logic and doesn't make
a whole lot of sense from a UX perspective.
Drop support for this. The argument should be an absolute path,
a relative path, or a formula name, rather than a hybrid.
cf. https://github.com/Homebrew/homebrew/issues/23430#issuecomment-26776962
Much of the name resolution done in Formula.canonical_name is repeated
Formulary.factory. Here we eliminate the repeated work by duplicating
the code from canonical_name. Later we will refactor it so that both
methods can share the bulk of the logic.
When the path argument to the Formula constructor is omitted, the
instance's path attribute is created using the Formula.path class
method. However, we have already done this work, so we can just pass it
into the constructor.
This translates to one less call to Pathname#to_s per formula, or about
2600 calls when running `brew readall`.