Module: Kernel

Defined in:
lib/fastlib.rb

Overview

Copyright © 2011 Rapid7. You can redistribute it and/or modify it under the terms of the ruby license.

Roughly based on the rubyzip zip/ziprequire library: >> Copyright © 2002 Thomas Sondergaard >> rubyzip is free software; you can redistribute it and/or >> modify it under the terms of the ruby license.

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)


75
76
77
78
# File 'lib/fastlib.rb', line 75

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)


89
90
91
92
# File 'lib/fastlib.rb', line 89

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

#fastlib_original_requireObject

:nodoc:all



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

alias :fastlib_original_require :require

#fastlib_require(name) ⇒ Object

This method handles the loading of FASTLIB archives



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/fastlib.rb', line 47

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

#require(name) ⇒ Object

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



40
41
42
# File 'lib/fastlib.rb', line 40

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