Class: Mutant::Zombifier

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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



27
28
29
30
31
# File 'lib/mutant/zombifier.rb', line 27

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



42
43
44
45
# File 'lib/mutant/zombifier.rb', line 42

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



66
67
68
# File 'lib/mutant/zombifier.rb', line 66

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



78
79
80
81
82
83
84
85
86
# File 'lib/mutant/zombifier.rb', line 78

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



55
56
57
58
# File 'lib/mutant/zombifier.rb', line 55

def run(logical_name)
  @highjack.infect
  require(logical_name)
end