Class: Mutant::Zombifier
- Inherits:
-
Object
- Object
- Mutant::Zombifier
- Includes:
- Adamantium::Flat
- Defined in:
- lib/mutant/zombifier.rb,
lib/mutant/zombifier/file.rb
Overview
Zombifier namespace
Defined Under Namespace
Classes: File
Constant Summary collapse
- INCLUDES =
%r{\A#{Regexp.union(includes)}(?:/.*)?\z}.freeze
Class Method Summary collapse
-
.run(logical_name, namespace) ⇒ self
private
Perform zombification of target library.
Instance Method Summary collapse
-
#include?(logical_name) ⇒ Boolean
private
Test if logical name is subjected to zombification.
-
#initialize(namespace) ⇒ undefined
constructor
private
Initialize object.
-
#require(logical_name) ⇒ self
private
Require file in zombie namespace.
-
#run(logical_name) ⇒ undefined
private
Run zombifier.
Constructor Details
#initialize(namespace) ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize object
26 27 28 29 30 |
# File 'lib/mutant/zombifier.rb', line 26 def initialize(namespace) @zombified = Set.new @highjack = RequireHighjack.new(Kernel, method(:require)) super(namespace) end |
Class Method Details
.run(logical_name, namespace) ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Perform zombification of target library
41 42 43 44 |
# File 'lib/mutant/zombifier.rb', line 41 def self.run(logical_name, namespace) new(namespace).run(logical_name) self end |
Instance Method Details
#include?(logical_name) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Test if logical name is subjected to zombification
65 66 67 |
# File 'lib/mutant/zombifier.rb', line 65 def include?(logical_name) !@zombified.include?(logical_name) && INCLUDES =~ logical_name end |
#require(logical_name) ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Require file in zombie namespace
77 78 79 80 81 82 83 84 85 |
# File 'lib/mutant/zombifier.rb', line 77 def require(logical_name) logical_name = logical_name.to_s @highjack.original.call(logical_name) return unless include?(logical_name) @zombified << logical_name file = File.find(logical_name) file.zombify(namespace) if file self end |
#run(logical_name) ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Run zombifier
54 55 56 57 |
# File 'lib/mutant/zombifier.rb', line 54 def run(logical_name) @highjack.infect require(logical_name) end |