2018-09-12 14:21:24 +00:00
|
|
|
# frozen_string_literal: true
|
2018-09-12 13:15:43 +00:00
|
|
|
|
2014-04-04 12:38:06 +00:00
|
|
|
module Mutant
|
|
|
|
# Require highjack
|
2015-06-06 22:29:47 +00:00
|
|
|
module RequireHighjack
|
2014-04-04 12:38:06 +00:00
|
|
|
|
2015-06-06 22:29:47 +00:00
|
|
|
# Install require callback
|
2014-04-04 12:38:06 +00:00
|
|
|
#
|
2015-06-06 22:29:47 +00:00
|
|
|
# @param [Module] target
|
|
|
|
# @param [#call] callback
|
2014-04-04 12:38:06 +00:00
|
|
|
#
|
2015-06-06 22:29:47 +00:00
|
|
|
# @return [#call]
|
|
|
|
# the original implementation on singleton
|
|
|
|
def self.call(target, callback)
|
2016-02-14 02:16:39 +00:00
|
|
|
target.public_method(:require).tap do
|
2015-06-06 22:29:47 +00:00
|
|
|
target.module_eval do
|
2016-02-14 02:16:39 +00:00
|
|
|
undef_method(:require)
|
2015-06-06 22:29:47 +00:00
|
|
|
define_method(:require, &callback)
|
2016-02-14 02:16:39 +00:00
|
|
|
class << self
|
|
|
|
undef_method(:require)
|
|
|
|
end
|
|
|
|
define_singleton_method(:require, &callback)
|
2014-04-04 12:38:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end # RequireHighjack
|
|
|
|
end # Mutant
|