class Mutest::Zombifier
Zombifier
namespace
Constants
- LoadError
Attributes
original[R]
Original require method
@return [Method]
Public Class Methods
call(*args)
click to toggle source
Call zombifier
@return [self]
# File lib/mutest/zombifier.rb, line 34 def self.call(*args) new(*args).__send__(:call) self end
new(*)
click to toggle source
Initialize object
@param [Symbol] namespace
@return [undefined]
Calls superclass method
# File lib/mutest/zombifier.rb, line 25 def initialize(*) super @includes = %r{\A#{Regexp.union(includes)}(?:/.*)?\z} @zombified = Set.new end
Private Instance Methods
call()
click to toggle source
Run zombifier
@return [undefined]
# File lib/mutest/zombifier.rb, line 49 def call @original = require_highjack.call(method(:require)) require(root_require) end
find(logical_name)
click to toggle source
Find file by logical path
@param [String] logical_name
@return [File]
@raise [LoadError]
otherwise
# File lib/mutest/zombifier.rb, line 85 def find(logical_name) file_name = "#{logical_name}.rb" load_path.each do |path| path = pathname.new(path).join(file_name) return path if path.file? end raise LoadError, "Cannot find file #{file_name.inspect} in load path" end
include?(logical_name)
click to toggle source
Test
if logical name is subjected to zombification
@param [String]
# File lib/mutest/zombifier.rb, line 57 def include?(logical_name) !@zombified.include?(logical_name) && includes =~ logical_name end
namespaced_node(source_path)
click to toggle source
Namespaced root node
@param [Pathname] source_path
@return [Parser::AST::Node]
# File lib/mutest/zombifier.rb, line 116 def namespaced_node(source_path) s(:module, s(:const, nil, namespace), Unparser.parse(source_path.read)) end
require(logical_name)
click to toggle source
Require file in zombie namespace
@param [#to_s] logical_name
@return [Bool]
true if successful and false if feature already loaded
# File lib/mutest/zombifier.rb, line 67 def require(logical_name) logical_name = logical_name.to_s loaded = original.call(logical_name) return loaded unless include?(logical_name) @zombified << logical_name zombify(find(logical_name)) true end
zombify(source_path)
click to toggle source
Zombify contents of file
Probably the 2nd valid use of eval ever. (First one is inserting mutests!).
@param [Pathname] source_path
@return [undefined]
# File lib/mutest/zombifier.rb, line 103 def zombify(source_path) kernel.eval( Unparser.unparse(namespaced_node(source_path)), TOPLEVEL_BINDING, source_path.to_s ) end