Sha256: f307d07ffcc3365ce1f09618259cd05f621d45e10ebf1d3bba20ac4dc1dd86b3

Contents?: true

Size: 1.74 KB

Versions: 14

Compression:

Stored size: 1.74 KB

Contents

module Mutant
  # Zombifier namespace
  class Zombifier
    include Adamantium::Flat, Concord.new(:namespace)

    # Excluded into zombification
    includes = %w[
      mutant
      unparser
      morpher
      adamantium
      equalizer
      anima
      concord
    ]

    INCLUDES = %r{\A#{Regexp.union(includes)}(?:/.*)?\z}.freeze

    # Initialize object
    #
    # @param [Symbol] namespace
    #
    # @return [undefined]
    #
    # @api private
    #
    def initialize(namespace)
      @zombified = Set.new
      @highjack = RequireHighjack.new(Kernel, method(:require))
      super(namespace)
    end

    # Perform zombification of target library
    #
    # @param [String] logical_name
    # @param [Symbol] namespace
    #
    # @return [self]
    #
    # @api private
    #
    def self.run(logical_name, namespace)
      new(namespace).run(logical_name)
      self
    end

    # Run zombifier
    #
    # @param [String] logical_name
    #
    # @return [undefined]
    #
    # @api private
    #
    def run(logical_name)
      @highjack.infect
      require(logical_name)
    end

    # Test if logical name is subjected to zombification
    #
    # @param [String]
    #
    # @api private
    #
    def include?(logical_name)
      !@zombified.include?(logical_name) && INCLUDES =~ logical_name
    end

    # Require file in zombie namespace
    #
    # @param [#to_s] logical_name
    #
    # @return [self]
    #
    # @api private
    #
    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

  end # Zombifier
end # Mutant

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
mutant-0.7.9 lib/mutant/zombifier.rb
mutant-0.7.8 lib/mutant/zombifier.rb
mutant-0.7.7 lib/mutant/zombifier.rb
mutant-0.7.6 lib/mutant/zombifier.rb
mutant-0.7.5 lib/mutant/zombifier.rb
mutant-0.7.4 lib/mutant/zombifier.rb
mutant-0.7.3 lib/mutant/zombifier.rb
mutant-0.7.2 lib/mutant/zombifier.rb
mutant-0.7.1 lib/mutant/zombifier.rb
mutant-0.6.7 lib/mutant/zombifier.rb
mutant-0.6.6 lib/mutant/zombifier.rb
mutant-0.6.5 lib/mutant/zombifier.rb
mutant-0.6.4 lib/mutant/zombifier.rb
mutant-0.6.3 lib/mutant/zombifier.rb