Formulary.factory always expects a string

This commit is contained in:
Adam Vandenberg 2013-06-23 12:47:10 -07:00
parent c2a5e3608c
commit 5c27f0ccb9

View File

@ -1,5 +1,4 @@
# The Formulary is responsible for creating instances # The Formulary is responsible for creating instances of Formula.
# of Formula.
class Formulary class Formulary
def self.formula_class_defined? formula_name def self.formula_class_defined? formula_name
@ -34,7 +33,6 @@ class Formulary
# have a "no such formula" message. # have a "no such formula" message.
raise raise
rescue LoadError, NameError rescue LoadError, NameError
# TODO - show exception details
raise FormulaUnavailableError.new(name) raise FormulaUnavailableError.new(name)
end end
end end
@ -99,13 +97,13 @@ class Formulary
end end
end end
# Loads formulae from URLs. # Loads formulae from URLs
class FromUrlLoader < FormulaLoader class FromUrlLoader < FormulaLoader
attr_reader :url attr_reader :url
def initialize url def initialize url
@url = url @url = url
@path = (HOMEBREW_CACHE_FORMULA/(File.basename(url))) @path = HOMEBREW_CACHE_FORMULA/File.basename(url)
@name = File.basename(url, '.rb') @name = File.basename(url, '.rb')
end end
@ -136,22 +134,12 @@ class Formulary
end end
# Return a Formula instance for the given reference. # Return a Formula instance for the given reference.
# `ref` may be: # `ref` is string containing:
# * a Formula instance, in which case it is returned # * a formula name
# TODO: is this code path used? # * a formula pathname
# * a Pathname to a local formula # * a formula URL
# * a string containing a formula pathname # * a local bottle reference
# * a string containing a formula URL
# * a string containing a formula name
# * a string containing a local bottle reference
def self.factory ref def self.factory ref
# If an instance of Formula is passed, just return it
return ref if ref.kind_of? Formula
# Otherwise, convert to String in case a Pathname comes in
# TODO - do we call with a Pathname instead of a string anywhere?
ref = ref.to_s
# If a URL is passed, download to the cache and install # If a URL is passed, download to the cache and install
if ref =~ %r[(https?|ftp)://] if ref =~ %r[(https?|ftp)://]
f = FromUrlLoader.new(ref) f = FromUrlLoader.new(ref)