Module: Kernel
- Defined in:
- lib/zip/ziprequire.rb
Instance Method Summary collapse
- #already_loaded?(moduleName) ⇒ Boolean
- #ensure_rb_extension(aString) ⇒ Object
- #get_resource(resourceName, &aProc) ⇒ Object
- #oldRequire ⇒ Object
- #require(moduleName) ⇒ Object
- #zip_require(moduleName) ⇒ Object
Instance Method Details
#already_loaded?(moduleName) ⇒ Boolean
49 50 51 52 |
# File 'lib/zip/ziprequire.rb', line 49 def already_loaded?(moduleName) moduleRE = Regexp.new("^"+moduleName+"(\.rb|\.so|\.dll|\.o)?$") $".detect { |e| e =~ moduleRE } != nil end |
#ensure_rb_extension(aString) ⇒ Object
54 55 56 |
# File 'lib/zip/ziprequire.rb', line 54 def ensure_rb_extension(aString) aString.sub(/(\.rb)?$/i, ".rb") end |
#get_resource(resourceName, &aProc) ⇒ Object
44 45 46 47 |
# File 'lib/zip/ziprequire.rb', line 44 def get_resource(resourceName, &aProc) zl = ZipList.new($:.grep(/\.zip$/)) zl.get_input_stream(resourceName, &aProc) end |
#oldRequire ⇒ Object
27 |
# File 'lib/zip/ziprequire.rb', line 27 alias :oldRequire :require |
#require(moduleName) ⇒ Object
29 30 31 |
# File 'lib/zip/ziprequire.rb', line 29 def require(moduleName) zip_require(moduleName) || oldRequire(moduleName) end |
#zip_require(moduleName) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/zip/ziprequire.rb', line 33 def zip_require(moduleName) return false if already_loaded?(moduleName) get_resource(ensure_rb_extension(moduleName)) { |zis| eval(zis.read); $" << moduleName } return true rescue Errno::ENOENT => ex return false end |