Article:
Xuất bản gem
1496
ngocdaothanh.myopenid.com 172Updated over 2 years ago |
Nếu như Perl có CPAN, PHP có PEAR, thì Ruby có RubyGem. Nếu project bạn đăng kí trên RubyForge thuộc dạng tiện ích command line hoặc thư viện, thì nên xuất bản theo dạng gem để có thể install dễ dàng bằng lệnh gem install <project_name>.

Để cụ thể dễ hiểu, xin trình bày qui trình dùng để xuất bản Revent.
Trong thư mục trunk, tạo tập tin revent.gemspec có nội dung sau:
Gem::Specification.new do |spec|
spec.name = 'revent'
spec.rubyforge_project = 'revent'
spec.version = '0.1'
spec.summary = 'RPC based on EventMachine'
spec.author = 'Ngoc DAO Thanh'
spec.email = 'ngocdaothanh@gmail.com'
spec.homepage = 'http://revent.rubyforge.org'
files = Dir.glob('**/*')
files.delete('revent.gemspec')
spec.files = files
spec.has_rdoc = false
end
Rồi chạy lệnh gem build revent.gemspec để tạo revent-0.1.gem. Kết quả lệnh trên như sau:
WARNING: RDoc will not be generated (has_rdoc == false)
Successfully built RubyGem
Name: revent
Version: 0.1
File: revent-0.1.gem
Trước hết ta thử install trên máy của chính mình bằng lệnh gem install revent-0.1.gem.
Nếu suôn sẻ thì ta upload revent-0.1.gem lên RubyForge, phải chọn kiểu tập tin là .gem để RubyForge tự động đăng kí với gem server.
Chờ vài tiếng, kiểm tra xem đã đăng kí xong chưa bằng lệnh gem search -r revent.
Revent chỉ gồm ít tập tin, nên qui trình xuất bản đơn giản. Với các project phức tạp hơn, nên dùng những tiện ích như New Gem.
Từ giữa tháng 11 năm 2009, RubyForge đã chuyển sang Gemcutter:
A few days ago we repointed gems.rubyforge.org to the gemcutter.org box. This means that Nick Quaranto's excellent gemcutter app is now indexing and serving all the gems - so rather than having two gem indexes, we now have one. As a consequence of this, when you release files to RubyForge you will probably also want to do a "gem push" to get them onto gemcutter and into the main gem index.
Note that you can continue to release gems (and other files) at RubyForge; it's just that gems won't automatically make it into the main gem index.
172
over 4 years ago
over 4 years ago