Module: Fastup

Extended by:
Fastup
Included in:
Fastup
Defined in:
lib/fastup.rb

Defined Under Namespace

Modules: XFile Classes: SearchPath

Instance Method Summary collapse

Instance Method Details

#apply!Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fastup.rb', line 4

def apply!
  warn "fastup: building load path index"
  sp = SearchPath.new($LOAD_PATH)
  suffixes = Gem.suffixes.lazy

  warn "fastup: patching require"
  mod = Module.new do
    define_method(:require) do |name|
      path = suffixes.map{ |s| sp.lookup(name.to_s + s) rescue nil }.find do |p|
        p && File.file?(p)
      end

      # require the absolute path if found, otherwise fallback to original name
      ret = super(path || name)

      if ret && ENV['FASTUP_DEBUG']
        if path
          warn "fastup: loaded #{name} => #{path}"
        else
          warn "fastup: super #{name}"
        end
      end

      ret
    end
  end
  Object.prepend mod
end