2013-06-28 17:23:05 -04:00
|
|
|
module Mutant
|
|
|
|
# Zombifier namespace
|
2014-04-04 10:14:24 -04:00
|
|
|
class Zombifier
|
|
|
|
include Adamantium::Flat, Concord.new(:namespace)
|
|
|
|
|
2014-04-04 11:46:55 -04:00
|
|
|
# Excluded into zombification
|
2014-05-27 11:12:36 -04:00
|
|
|
includes = %w[
|
2014-04-04 11:46:55 -04:00
|
|
|
mutant
|
|
|
|
morpher
|
|
|
|
adamantium
|
|
|
|
equalizer
|
|
|
|
anima
|
|
|
|
concord
|
2014-05-27 11:12:36 -04:00
|
|
|
]
|
2014-04-04 11:46:55 -04:00
|
|
|
|
2014-05-27 11:12:36 -04:00
|
|
|
INCLUDES = %r{\A#{Regexp.union(includes)}(?:/.*)?\z}.freeze
|
2014-04-04 10:14:24 -04:00
|
|
|
|
|
|
|
# Initialize object
|
|
|
|
#
|
|
|
|
# @param [Symbol] namespace
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def initialize(namespace)
|
2014-04-04 11:46:55 -04:00
|
|
|
@zombified = Set.new
|
|
|
|
@highjack = RequireHighjack.new(Kernel, method(:require))
|
2014-04-20 14:27:05 -04:00
|
|
|
super(namespace)
|
2014-04-04 10:14:24 -04:00
|
|
|
end
|
2013-06-28 17:23:05 -04:00
|
|
|
|
2014-04-04 10:14:24 -04:00
|
|
|
# Perform zombification of target library
|
|
|
|
#
|
|
|
|
# @param [String] logical_name
|
|
|
|
# @param [Symbol] namespace
|
2013-06-28 17:23:05 -04:00
|
|
|
#
|
2014-04-04 10:14:24 -04:00
|
|
|
# @api private
|
2013-06-28 17:23:05 -04:00
|
|
|
#
|
2014-04-04 10:14:24 -04:00
|
|
|
def self.run(logical_name, namespace)
|
|
|
|
new(namespace).run(logical_name)
|
|
|
|
end
|
2013-06-28 17:23:05 -04:00
|
|
|
|
2014-04-04 10:14:24 -04:00
|
|
|
# Run zombifier
|
2013-06-28 17:23:05 -04:00
|
|
|
#
|
2014-04-04 10:14:24 -04:00
|
|
|
# @param [String] logical_name
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
2013-06-28 17:23:05 -04:00
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-04-04 10:14:24 -04:00
|
|
|
def run(logical_name)
|
2014-04-04 11:46:55 -04:00
|
|
|
@highjack.infect
|
2014-04-04 10:14:24 -04:00
|
|
|
require(logical_name)
|
2013-06-28 17:23:05 -04:00
|
|
|
end
|
|
|
|
|
2014-04-04 11:46:55 -04:00
|
|
|
# Test if logical name is subjected to zombification
|
|
|
|
#
|
|
|
|
# @param [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def include?(logical_name)
|
|
|
|
!@zombified.include?(logical_name) && INCLUDES =~ logical_name
|
|
|
|
end
|
|
|
|
|
2014-04-04 10:14:24 -04:00
|
|
|
# Require file in zombie namespace
|
2013-06-28 17:23:05 -04:00
|
|
|
#
|
2014-06-15 11:50:38 -04:00
|
|
|
# @param [#to_s] logical_name
|
2013-06-28 17:23:05 -04:00
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
2014-04-04 10:14:24 -04:00
|
|
|
def require(logical_name)
|
2014-06-15 11:50:38 -04:00
|
|
|
logical_name = logical_name.to_s
|
2014-04-04 11:46:55 -04:00
|
|
|
@highjack.original.call(logical_name)
|
|
|
|
return unless include?(logical_name)
|
2014-04-04 10:14:24 -04:00
|
|
|
@zombified << logical_name
|
2014-04-04 10:18:45 -04:00
|
|
|
file = File.find(logical_name)
|
2014-04-04 10:14:24 -04:00
|
|
|
file.zombify(namespace) if file
|
2013-09-07 14:19:42 -04:00
|
|
|
self
|
2013-06-28 17:23:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end # Zombifier
|
|
|
|
end # Mutant
|