Module: Kernel

Defined in:
lib/fastlib.rb

Overview

:nodoc:all

Instance Method Summary collapse

Instance Method Details

#fastlib_already_loaded?(name) ⇒ Boolean

This method determines whether the specific file name has already been loaded ($LOADED_FEATURES aka $“)

Returns:

  • (Boolean)


400
401
402
403
# File 'lib/fastlib.rb', line 400

def fastlib_already_loaded?(name)
	re = Regexp.new("^" + Regexp.escape(name) + "$")
	$".detect { |e| e =~ re } != nil
end

#fastlib_already_tried?(name) ⇒ Boolean

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.

Returns:

  • (Boolean)


414
415
416
417
# File 'lib/fastlib.rb', line 414

def fastlib_already_tried?(name)
	$fastlib_miss ||= []
	$fastlib_miss.include?(name)
end

#fastlib_original_requireObject



354
# File 'lib/fastlib.rb', line 354

alias :fastlib_original_require :require

#fastlib_require(name) ⇒ Object

This method handles the loading of FASTLIB archives



367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
# File 'lib/fastlib.rb', line 367

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

#require(name) ⇒ Object

This method hooks the original Kernel.require to support loading files within FASTLIB archives



360
361
362
# File 'lib/fastlib.rb', line 360

def require(name)
	fastlib_require(name) || fastlib_original_require(name)
end