FormulaLoader: pull shared behavior into superclass

This commit is contained in:
Jack Nagel 2014-03-07 17:23:44 -06:00
parent 452d671008
commit d476a84f4f

View File

@ -38,8 +38,9 @@ class Formulary
attr_reader :path attr_reader :path
# Gets the formula instance. # Gets the formula instance.
# Subclasses must define this. def get_formula
def get_formula; end klass.new(name, path)
end
# Return the Class for this formula, `require`-ing it if # Return the Class for this formula, `require`-ing it if
# it has not been parsed before. # it has not been parsed before.
@ -89,9 +90,9 @@ class Formulary
end end
def get_formula def get_formula
formula = klass.new(name, path) formula = super
formula.local_bottle_path = @bottle_filename formula.local_bottle_path = @bottle_filename
return formula formula
end end
end end
@ -101,10 +102,6 @@ class Formulary
@name = name @name = name
@path = Formula.path(name) @path = Formula.path(name)
end end
def get_formula
klass.new(name, path)
end
end end
# Loads formulae from disk using a path # Loads formulae from disk using a path
@ -117,10 +114,6 @@ class Formulary
@path = Pathname.new(path).expand_path @path = Pathname.new(path).expand_path
@name = @path.stem @name = @path.stem
end end
def get_formula
klass.new(name, path)
end
end end
# Loads formulae from URLs # Loads formulae from URLs
@ -143,7 +136,8 @@ class Formulary
end end
def get_formula def get_formula
return klass.new(name, path) fetch
super
end end
end end
@ -155,7 +149,7 @@ class Formulary
end end
def get_formula def get_formula
klass.new(name, path) super
rescue FormulaUnavailableError => e rescue FormulaUnavailableError => e
raise TapFormulaUnavailableError.new(e.name) raise TapFormulaUnavailableError.new(e.name)
end end
@ -171,7 +165,6 @@ class Formulary
# 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)
f.fetch
elsif ref =~ Pathname::BOTTLE_EXTNAME_RX elsif ref =~ Pathname::BOTTLE_EXTNAME_RX
f = BottleLoader.new(ref) f = BottleLoader.new(ref)
else else