versions: restore original constant
Before:
f1 = Formula.factory('tree')
f1.versions
f2 = Formula.factory('tree')
f1.class == f2.class # => false
After:
f1 = Formula.factory('tree')
f1.versions
f2 = Formula.factory('tree')
f1.class == f2.class # => true
This commit is contained in:
parent
b6cbd08e93
commit
a933b58507
@ -108,7 +108,7 @@ class Formula
|
|||||||
|
|
||||||
# Unload the class so Formula#version returns the correct value
|
# Unload the class so Formula#version returns the correct value
|
||||||
begin
|
begin
|
||||||
Formulary.unload_formula name
|
old_const = Formulary.unload_formula name
|
||||||
nostdout { yield Formula.factory(path.to_s) }
|
nostdout { yield Formula.factory(path.to_s) }
|
||||||
rescue *IGNORED_EXCEPTIONS => e
|
rescue *IGNORED_EXCEPTIONS => e
|
||||||
# We rescue these so that we can skip bad versions and
|
# We rescue these so that we can skip bad versions and
|
||||||
@ -116,6 +116,8 @@ class Formula
|
|||||||
ohai "#{e} in #{name} at revision #{sha}", e.backtrace if ARGV.debug?
|
ohai "#{e} in #{name} at revision #{sha}", e.backtrace if ARGV.debug?
|
||||||
rescue FormulaUnavailableError
|
rescue FormulaUnavailableError
|
||||||
# Suppress this error
|
# Suppress this error
|
||||||
|
ensure
|
||||||
|
Formulary.restore_formula name, old_const
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -13,6 +13,13 @@ class Formulary
|
|||||||
Object.const_get(Formula.class_s(formula_name))
|
Object.const_get(Formula.class_s(formula_name))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.restore_formula formula_name, value
|
||||||
|
old_verbose, $VERBOSE = $VERBOSE, nil
|
||||||
|
Object.const_set(Formula.class_s(formula_name), value)
|
||||||
|
ensure
|
||||||
|
$VERBOSE = old_verbose
|
||||||
|
end
|
||||||
|
|
||||||
# A FormulaLoader returns instances of formulae.
|
# A FormulaLoader returns instances of formulae.
|
||||||
# Subclasses implement loaders for particular sources of formulae.
|
# Subclasses implement loaders for particular sources of formulae.
|
||||||
class FormulaLoader
|
class FormulaLoader
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user