Sha256: d4e83fbb51734c1f84c550abd9785ebe0c4addd32b71658e9b1dca96c5684356

Contents?: true

Size: 1.33 KB

Versions: 113

Compression:

Stored size: 1.33 KB

Contents

require 'zip/zip'

class ZipList
  def initialize(zipFileList)
      @zipFileList = zipFileList
  end

  def get_input_stream(entry, &aProc)
    @zipFileList.each {
      |zfName|
      Zip::ZipFile.open(zfName) {
	|zf|
	begin
	  return zf.get_input_stream(entry, &aProc) 
	rescue Errno::ENOENT
	end
      }
    }
    raise Errno::ENOENT,
      "No matching entry found in zip files '#{@zipFileList.join(', ')}' "+
      " for '#{entry}'"
  end
end


module Kernel
  alias :oldRequire :require

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

  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

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

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

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

# Copyright (C) 2002 Thomas Sondergaard
# rubyzip is free software; you can redistribute it and/or
# modify it under the terms of the ruby license.

Version data entries

113 entries across 113 versions & 16 rubygems

Version Path
bigtinker-0.93 extras/zip/ziprequire.rb
bigtinker-0.94 extras/zip/ziprequire.rb
bigtinker-0.96 lib/zip/ziprequire.rb
bigtinker-0.95 lib/zip/ziprequire.rb
bigtinker-0.97 lib/zip/ziprequire.rb
rubyslippers-1.01 extras/zip/ziprequire.rb
rubyslippers-1.00 extras/zip/ziprequire.rb
rubyslippers-1.02 extras/zip/ziprequire.rb
rubyslippers-1.06 extras/zip/ziprequire.rb
rubyslippers-1.04 extras/zip/ziprequire.rb
rubyslippers-1.03 extras/zip/ziprequire.rb
rubyslippers-0.99 extras/zip/ziprequire.rb
rubyslippers-1.07 lib/zip/ziprequire.rb
rubyslippers-1.08 lib/zip/ziprequire.rb
rwdaddresses-1.01 extras/zip/ziprequire.rb
rwdaddresses-0.98 extras/zip/ziprequire.rb
rwdaddresses-0.99 extras/zip/ziprequire.rb
rwdaddresses-1.02 extras/zip/ziprequire.rb
rwdaddresses-1.03 extras/zip/ziprequire.rb
rwdaddresses-1.05 lib/zip/ziprequire.rb