extract: use localized monkey-patching
Instead of just blanketing over with monkey-patches like before, set up monkey-patches as needed, and make sure to clean up after we're done.
This commit is contained in:
parent
a8563afc9e
commit
bd352bcf35
@ -15,28 +15,49 @@ require "utils/git"
|
|||||||
require "formulary"
|
require "formulary"
|
||||||
require "tap"
|
require "tap"
|
||||||
|
|
||||||
# rubocop:disable Style/MethodMissingSuper
|
def with_monkey_patch
|
||||||
class BottleSpecification
|
BottleSpecification.class_eval do
|
||||||
def method_missing(*); end
|
if method_defined?(:method_missing)
|
||||||
|
alias_method :old_method_missing, :method_missing
|
||||||
def respond_to_missing?(*)
|
end
|
||||||
true
|
define_method(:method_missing) { |*| }
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
class Module
|
Module.class_eval do
|
||||||
def method_missing(*); end
|
if method_defined?(:method_missing)
|
||||||
|
alias_method :old_method_missing, :method_missing
|
||||||
def respond_to_missing?(*)
|
end
|
||||||
true
|
define_method(:method_missing) { |*| }
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
class Resource
|
Resource.class_eval do
|
||||||
def method_missing(*); end
|
if method_defined?(:method_missing)
|
||||||
|
alias_method :old_method_missing, :method_missing
|
||||||
|
end
|
||||||
|
define_method(:method_missing) { |*| }
|
||||||
|
end
|
||||||
|
|
||||||
def respond_to_missing?(*)
|
yield
|
||||||
true
|
ensure
|
||||||
|
BottleSpecification.class_eval do
|
||||||
|
if method_defined?(:old_method_missing)
|
||||||
|
alias_method :method_missing, :old_method_missing
|
||||||
|
undef :old_method_missing
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Module.class_eval do
|
||||||
|
if method_defined?(:old_method_missing)
|
||||||
|
alias_method :method_missing, :old_method_missing
|
||||||
|
undef :old_method_missing
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Resource.class_eval do
|
||||||
|
if method_defined?(:old_method_missing)
|
||||||
|
alias_method :method_missing, :old_method_missing
|
||||||
|
undef :old_method_missing
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -52,7 +73,6 @@ class DependencyCollector
|
|||||||
prepend Compat
|
prepend Compat
|
||||||
end
|
end
|
||||||
|
|
||||||
# rubocop:enable Style/MethodMissingSuper
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
@ -135,6 +155,6 @@ module Homebrew
|
|||||||
contents = Git.last_revision_of_file(repo, file, before_commit: rev)
|
contents = Git.last_revision_of_file(repo, file, before_commit: rev)
|
||||||
contents.gsub!("@url=", "url ")
|
contents.gsub!("@url=", "url ")
|
||||||
contents.gsub!("require 'brewkit'", "require 'formula'")
|
contents.gsub!("require 'brewkit'", "require 'formula'")
|
||||||
Formulary.from_contents(name, file, contents)
|
with_monkey_patch { Formulary.from_contents(name, file, contents) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user