Module: Kernel

Defined in:
lib/pik/contrib/zip/ziprequire.rb

Overview

:nodoc:all

Instance Method Summary collapse

Instance Method Details

#already_loaded?(moduleName) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
81
# File 'lib/pik/contrib/zip/ziprequire.rb', line 78

def already_loaded?(moduleName)
  moduleRE = Regexp.new("^"+moduleName+"(\.rb|\.so|\.dll|\.o)?$")
  $".detect { |e| e =~ moduleRE } != nil
end

#ensure_rb_extension(aString) ⇒ Object



83
84
85
# File 'lib/pik/contrib/zip/ziprequire.rb', line 83

def ensure_rb_extension(aString)
  aString.sub(/(\.rb)?$/i, ".rb")
end

#get_resource(resourceName, &aProc) ⇒ Object



73
74
75
76
# File 'lib/pik/contrib/zip/ziprequire.rb', line 73

def get_resource(resourceName, &aProc)
  zl = ZipList.new($:.grep(/\.zip$/))
  zl.get_input_stream(resourceName, &aProc)
end

#oldRequireObject



56
# File 'lib/pik/contrib/zip/ziprequire.rb', line 56

alias :oldRequire :require

#require(moduleName) ⇒ Object



58
59
60
# File 'lib/pik/contrib/zip/ziprequire.rb', line 58

def require(moduleName)
  zip_require(moduleName) || oldRequire(moduleName)
end

#zip_require(moduleName) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/pik/contrib/zip/ziprequire.rb', line 62

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