2013-07-28 19:03:06 -04:00
|
|
|
# encoding: utf-8
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
# Excluded from zombification
|
|
|
|
IGNORE = [
|
|
|
|
# Unparser is not performant enough (does some backtracking!) for generated lexer.rb
|
|
|
|
'parser',
|
|
|
|
'parser/all',
|
|
|
|
'parser/current',
|
|
|
|
# Wierd constant definitions / guards.
|
|
|
|
'diff/lcs',
|
|
|
|
'diff/lcs/hunk',
|
|
|
|
# Mix beteen constants defined in .so and .rb files
|
|
|
|
# Cannot be deterministically namespaced from ruby
|
|
|
|
# without dynamically recompiling openssl ;)
|
|
|
|
'openssl',
|
|
|
|
# Constant propagation errors
|
2014-04-04 10:28:33 -04:00
|
|
|
'thread_safe',
|
|
|
|
# Unparser errors!
|
|
|
|
'time'
|
2014-04-04 10:14:24 -04:00
|
|
|
].to_set.freeze
|
|
|
|
|
|
|
|
# Initialize object
|
|
|
|
#
|
|
|
|
# @param [Symbol] namespace
|
|
|
|
#
|
|
|
|
# @return [undefined]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def initialize(namespace)
|
|
|
|
@namespace = namespace
|
|
|
|
@zombified = Set.new(IGNORE)
|
|
|
|
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)
|
|
|
|
highjack = RequireHighjack.new(Kernel, method(:require))
|
|
|
|
highjack.infect
|
|
|
|
require(logical_name)
|
2013-06-28 17:23:05 -04:00
|
|
|
end
|
|
|
|
|
2014-04-04 10:14:24 -04:00
|
|
|
# Require file in zombie namespace
|
2013-06-28 17:23:05 -04:00
|
|
|
#
|
2014-04-04 10:14:24 -04:00
|
|
|
# @param [String] 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)
|
|
|
|
return if @zombified.include?(logical_name)
|
|
|
|
@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
|