50 lines
981 B
Ruby
50 lines
981 B
Ruby
|
module Mutant
|
||
|
class Zombifier
|
||
|
# File containing source beeing zombified
|
||
|
class File
|
||
|
include NodeHelpers, Adamantium::Flat, Concord::Public.new(:path)
|
||
|
|
||
|
# Zombify contents of file
|
||
|
#
|
||
|
# @return [self]
|
||
|
#
|
||
|
# @api private
|
||
|
#
|
||
|
def zombify(namespace)
|
||
|
$stderr.puts("Zombifying #{path.to_s}")
|
||
|
eval(
|
||
|
Unparser.unparse(namespaced_node(namespace)),
|
||
|
TOPLEVEL_BINDING,
|
||
|
path.to_s
|
||
|
)
|
||
|
self
|
||
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
# Return node
|
||
|
#
|
||
|
# @return [Parser::AST::Node]
|
||
|
#
|
||
|
# @api private
|
||
|
#
|
||
|
def node
|
||
|
Parser::CurrentRuby.parse(path.read)
|
||
|
end
|
||
|
|
||
|
# Return namespaced root
|
||
|
#
|
||
|
# @param [Symbol] namespace
|
||
|
#
|
||
|
# @return [Parser::AST::Node]
|
||
|
#
|
||
|
# @api private
|
||
|
#
|
||
|
def namespaced_node(namespace)
|
||
|
s(:module, s(:const, nil, namespace), node)
|
||
|
end
|
||
|
|
||
|
end # File
|
||
|
end # Zombifier
|
||
|
end # Mutant
|