Advertisement
Guest User

fastlib

a guest
Nov 16th, 2012
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.06 KB | None | 0 0
  1. module Kernel #:nodoc:all
  2.     alias :fastlib_original_require :require
  3.    
  4.     #
  5.     # Store the CWD when were initially loaded
  6.     # required for resolving relative paths
  7.     #
  8.     @@fastlib_base_cwd = ::Dir.pwd
  9.  
  10.     #
  11.     # This method hooks the original Kernel.require to support
  12.     # loading files within FASTLIB archives
  13.     #  
  14.     def require(name)
  15.         fastlib_require(name) || fastlib_original_require(name)
  16.     end
  17.    
  18.     #
  19.     # This method handles the loading of FASTLIB archives
  20.     #
  21.     def fastlib_require(name)
  22.         name = name + ".rb" if not name =~ /\.rb$/
  23.         return false if fastlib_already_loaded?(name)
  24.         return false if fastlib_already_tried?(name)
  25.  
  26.         # XXX Implement relative search paths within archives
  27.         $:.map{ |path|
  28.             (path =~ /^([A-Za-z]\:|\/)/ ) ? path : ::File.expand_path( ::File.join(@@fastlib_base_cwd, path) )
  29.         }.map{  |path| ::Dir["#{path}/*.fastlib"] }.flatten.uniq.each do |lib|
  30.             data = FastLib.load(lib, name)
  31.             next if not data
  32.             $" << name
  33.            
  34.             Object.class_eval(data, lib + "::" + name)
  35.  
  36.             return true
  37.         end
  38.        
  39.         $fastlib_miss << name  
  40.  
  41.         false
  42.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement