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

Parameters:

  • namespace (Symbol)


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

Parameters:

  • logical_name (String)
  • namespace (Symbol)

Returns:

  • (self)


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

Parameters:

  • (String)

Returns:

  • (Boolean)


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

Parameters:

  • logical_name (#to_s)

Returns:

  • (self)


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

Parameters:

  • logical_name (String)

Returns:

  • (undefined)


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

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