ziprequire.rb

Path: lib/zip/ziprequire.rb
Last Update: Sun Aug 24 13:00:55 +0200 2008

With ziprequire you can load ruby modules from a zip file. This means ruby‘s module include path can include zip-files.

The following example creates a zip file with a single entry log/simplelog.rb that contains a single function simpleLog:

  require 'zip/zipfilesystem'

  Zip::ZipFile.open("my.zip", true) {
    |zf|
    zf.file.open("log/simplelog.rb", "w") {
      |f|
      f.puts "def simpleLog(v)"
      f.puts '  Kernel.puts "INFO: #{v}"'
      f.puts "end"
    }
  }

To use the ruby module stored in the zip archive simply require zip/ziprequire and include the my.zip zip file in the module search path. The following command shows one way to do this:

  ruby -rzip/ziprequire -Imy.zip  -e " require 'log/simplelog'; simpleLog 'Hello world' "

Required files

zip/zip  

[Validate]