我正在创造我期望的红宝石宝石.任何人都有一个很好的链接指向将简单的库或插件转换为gem的教程?另外,特别是,Ruby使用什么来允许需要查找宝石?它似乎不仅仅是将文件放在gem路径中(或者我的配置搞砸了?).
谢谢
实际上并不难以手动执行此操作.假设您有一个whatever.rb
要作为gem分发的库.
建立一个目录lib
,并把副本whatever.rb
在lib/whatever.rb
.
制作一个文件whatever.gemspec
,并在其中放入以下内容,填写适当的值:
Gem::Specification.new do |spec| spec.name = 'the-name-of-your-gem' spec.version ='0.0.1'
# this is important - it specifies which files to include in the gem. spec.files = ["lib/whatever.rb"]
# optional, but useful to your users spec.summary = "A more longwinded description of your gem" spec.author = 'Your Name' spec.email = 'you@yourdomain.com' spec.homepage = 'http://www.yourpage.com'
# you did document with RDoc, right? spec.has_rdoc = true
# if you have a ruby forge project spec.rubyforge_project = 'your-project-name-on-rubyforge'
# if you have any dependencies on other gems, list them thusly spec.add_dependency('hpricot') spec.add_dependency('log4r', '>= 1.0.5') end
现在,要构建gem,请使用以下gem build
命令:
% gem build whatever.gemspec Successfully built RubyGem Name: the-name-of-your-gem Version: 0.0.1 File: the-name-of-your-gem-0.0.1.gem %
您可以gem install the-name-of-your-gem-0.0.1.gem
使用在脚本中使用库来本地测试,然后在顶部执行以下操作:
require 'rubygems' # puts gem libraries in the require path require 'whatever' # loads your library
有关gemspec
文件中各种设置的更多信息,请查看GemSpec参考.
就个人而言,我也使用rubygems来打包可执行脚本,并且发现它非常方便.