Permalink
Browse files

Load all .fastlib's from the include path

  • Loading branch information...
1 parent 09803dd commit b828e7b974db9076cfda6a0c18d4406266a7a609 HD Moore committed Nov 24, 2011
Showing with 70 additions and 63 deletions.
  1. +70 −63 lib/fastlib.rb
View
@@ -31,75 +31,13 @@
# >> rubyzip is free software; you can redistribute it and/or
# >> modify it under the terms of the ruby license.
-module Kernel #:nodoc:all
- alias :fastlib_original_require :require
-
- #
- # This method hooks the original Kernel.require to support
- # loading files within FASTLIB archives
- #
- def require(name)
- fastlib_require(name) || fastlib_original_require(name)
- end
-
- #
- # This method handles the loading of FASTLIB archives
- #
- def fastlib_require(name)
- name = name + ".rb" if not name =~ /\.rb$/
- return false if fastlib_already_loaded?(name)
- return false if fastlib_already_tried?(name)
-
- # TODO: Implement relative path $: checks and adjust the
- # search path within archives to match.
-
- $:.grep( /^(.*)\.fastlib$/ ).each do |lib|
- data = FastLib.load(lib, name)
- next if not data
- $" << name
-
- # TODO: Implement a better stack trace that represents
- # the original filename and line number.
- Object.class_eval(data)
- return true
- end
-
- $fastlib_miss << name
-
- false
- end
-
- #
- # This method determines whether the specific file name
- # has already been loaded ($LOADED_FEATURES aka $")
- #
- def fastlib_already_loaded?(name)
- re = Regexp.new("^" + Regexp.escape(name) + "$")
- $".detect { |e| e =~ re } != nil
- end
-
- #
- # This method determines whether the specific file name
- # has already been attempted with the included FASTLIB
- # archives.
- #
- # TODO: Ensure that this only applies to known FASTLIB
- # archives and that newly included archives will
- # be searched appropriately.
- #
- def fastlib_already_tried?(name)
- $fastlib_miss ||= []
- $fastlib_miss.include?(name)
- end
-end
-
#
# The FastLib class implements the meat of the FASTLIB archive format
#
class FastLib
- VERSION = "0.0.5"
+ VERSION = "0.0.6"
FLAG_COMPRESS = 0x01
FLAG_ENCRYPT = 0x02
@@ -403,4 +341,73 @@ def self.cache
=end
+module Kernel #:nodoc:all
+ alias :fastlib_original_require :require
+
+ #
+ # This method hooks the original Kernel.require to support
+ # loading files within FASTLIB archives
+ #
+ def require(name)
+ fastlib_require(name) || fastlib_original_require(name)
+ end
+
+ #
+ # This method handles the loading of FASTLIB archives
+ #
+ def fastlib_require(name)
+ name = name + ".rb" if not name =~ /\.rb$/
+ return false if fastlib_already_loaded?(name)
+ return false if fastlib_already_tried?(name)
+
+ # TODO: Implement relative path $: checks and adjust the
+ # search path within archives to match.
+
+ $:.map{ |path| ::Dir["#{path}/*.fastlib"] }.flatten.uniq.each do |lib|
+ data = FastLib.load(lib, name)
+ next if not data
+ $" << name
+
+ begin
+ Object.class_eval(data)
+ rescue ::Exception => e
+ opath,oerror = e.backtrace.shift.split(':', 2)
+ e.backtrace.unshift("#{lib}::#{name}:#{oerror}")
+ raise e
+ end
+
+ return true
+ end
+
+ $fastlib_miss << name
+
+ false
+ end
+
+ #
+ # This method determines whether the specific file name
+ # has already been loaded ($LOADED_FEATURES aka $")
+ #
+ def fastlib_already_loaded?(name)
+ re = Regexp.new("^" + Regexp.escape(name) + "$")
+ $".detect { |e| e =~ re } != nil
+ end
+
+ #
+ # This method determines whether the specific file name
+ # has already been attempted with the included FASTLIB
+ # archives.
+ #
+ # TODO: Ensure that this only applies to known FASTLIB
+ # archives and that newly included archives will
+ # be searched appropriately.
+ #
+ def fastlib_already_tried?(name)
+ $fastlib_miss ||= []
+ $fastlib_miss.include?(name)
+ end
+end
+
+
+

0 comments on commit b828e7b

Please sign in to comment.