寻找rubygems的好处 [英] Gotchas for writing rubygems
问题描述
在如何 写 rubygems,但在写rubygem时应该避免什么?什么可能会导致人们使用你的rubygem的问题?
Gem Packaging:Best Practices 提供了很多建议,其中一些包括-
不要污染全局负载路径。理想情况下,在
lib
目录中只有foo.rb
,并将所有其他文件放在lib / foo
。 -
不要使用
code> __ FILE __
。 -
不要依赖加载路径之外的任何内容。文件夹可能与原始版本中的结构不同。例如,不要使用类似于
VERSION = :: File.read(:: File.join(:: File.dirname( FILE < strip)
-
不要管理
$($ strong>),..,..,VERSION))。 LOAD_PATH
lib
。 提供
VERSION
常量。 不要依赖rubygems。使用你的代码的人可能不会使用rubygems,而是使用其他一些包装系统(或者没有包装系统)。同样,不要在代码本身中提及版本依赖关系,或者 rescue Gem :: LoadError
。 Rubygems依赖关系。请... 指出,您不应该列出可选的运行时依赖项,并且应该将开发者与运行时依赖项分开。
/github.com/agrimm/zombie-chaser/commit/0a888b2ea33481e078ab7640c9fd38dc6a23710frel =nofollow noreferrer>从我自己的经历来看:如果没有别的,尝试在本地创建并安装您的gem,然后将其释放到野外。它避免了牛皮纸袋的发行。There have been questions with answers on how to write rubygems, but what should you avoid in writing a rubygem? What can cause problems for people using your rubygem?
Gem Packaging: Best Practices gives a lot of advice, some of which include
Don't pollute the global load path. Ideally, only have
foo.rb
in yourlib
directory, and put all your other files inlib/foo
.Don't
require
files using__FILE__
.Don't rely on anything outside the load path. Folders may not have the same structure as in your original version. For example, don't use something like
VERSION = ::File.read(::File.join(::File.dirname(FILE), "..", "..", "VERSION")).strip
Don't manage
$LOAD_PATH
withinlib
.Provide a
VERSION
constant.Don't depend on rubygems. The person using your code may not be using rubygems, but some other packaging system (or no packaging system). Similarly, don't mention version dependencies in the code itself, or
rescue Gem::LoadError
.
Rubygems dependencies. Please... argues that you shouldn't list optional runtime dependencies, and should separate developer from runtime dependencies.
From my own experience: if nothing else, try building and installing your gem locally before releasing it into the wild. It avoids brown paper bag releases.
这篇关于寻找rubygems的好处的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!