从 zip 存档加载 ruby 源代码?
我有一个 mod_rails 服务器,奇怪的是,它的磁盘空间非常宝贵。有没有办法让我压缩应用程序的源代码,例如 Python 的 zipimport?
这样做有明显的缺点,所以我可能应该崩溃并在磁盘空间上花一点钱,但我认为值得一试。
I have a mod_rails server where disk space, oddly enough, is at a premium. Is there a way for me to compress my application's source, like Python's zipimport?
There are obvious disadvantages to this, so I should probably just break down and spend a nickel on disk space, but I figured it'd be worth a shot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
哦,这很整洁。查看 rubyzip gem:
(更新: ziprequire.rb 不再存在于 rubyzip gem 中,但是 源 链接似乎仍然包含其旧内容。)
就像这样。这只是对他们的示例稍作修改:
当然,您不必使用 rubyzip 库来创建压缩库。您可以使用 CLI zip 来实现这一点。
Oh, this is neat. Check out the rubyzip gem:
(Update: The ziprequire.rb is no longer present in the rubyzip gem, but the source link appears to contain its old content nonetheless.)
Like so. This is just slightly modified from their example:
You don't have to use the rubyzip library to create the zipped library, of course. You can use CLI zip for that.
require
和load
只是与其他方法一样的方法。您可以取消定义它们、重新定义它们、覆盖它们、挂钩它们、包装它们以执行您想要的任何操作。事实上,这正是 RubyGems 的工作原理。现在,我不知道是否有人已经为您实现了这个,但我实际上记得 ruby-talk 邮件列表。
但是,有一些从替代位置加载库代码的示例可供您查看,并且可以复制/调整它们正在为您的目的所做的事情:
需要
HTTP URIrequire
以从(加密的)SQLite 数据库而不是文件系统加载库require
andload
are just methods like any other. You can undefine them, redefine them, override them, hook them, wrap them to do anything you want. In fact, that's exactly how RubyGems works.Now, I don't know whether someone has already implemented this for you, but I actually remember some discussions about this on the ruby-talk mailinglist.
However, there are some examples of loading library code from alternative locations that you can look at, and maybe copy / adapt what they are doing for your purpose:
require
an HTTP URIrequire
to load libraries out of an (encrypted) SQLite database instead of the filesystem