1. Install gem gemcutter dan jeweler. Perlu diketahui, versi jeweler yang digunakan saat membuat artikel ini adalah 1.4.0
gem install gemcutter gem install jeweler2. Jalankan perintah jeweler
jeweler hello-world3. Masuk ke dalam direktori hello-world, kemudian buka file hello-world.rb di dalam direktori lib dan tulis kode seperti di bawah ini.
# hello-world/lib/hello-world.rb puts "hello world!"4. Buka file Rakefile dan isikan sebagai berikut.
#----------------cut---------------
Jeweler::Tasks.new do |gem|
gem.name = "hello-world"
gem.summary = "one-line summary of your gem"
gem.description = "longer description of your gem"
gem.email = "youremail@example.com"
gem.homepage = "http://github.com/kuntoaji/hello-world"
gem.authors = ["firsname lastname"]
end
#----------------cut---------------
5. Buat versi gem, build dan install gemrake version:write rake build rake install # disarakan sebagai root saat menjalakan perintah ini6. Langkah terakhir, berikut ini adalah kode untuk menggunakan gem hello-world
require 'rubygems' require 'hello-world'
Berikut ini adalah langkah-langkah untuk merilis gem yang telah kita buat ke publik dengan cara memasukkan ke dalam repositori gemcutter dan akun github:
git add . git commit -am "this is hello world gem" rake release
Sebagai informasi tambahan, jalakan perintah rake -T untuk mengetahui task apa saja yang tersedia untuk membangun sebuah gem.
aji@slacky:~/lab/hello-world$ rake -T (in /home/aji/lab/hello-world) rake build # Build gem rake check_dependencies # Check that runtime and development dependencies are installed rake check_dependencies:development # Check that development dependencies are installed rake check_dependencies:runtime # Check that runtime dependencies are installed rake clobber_rdoc # Remove rdoc products rake gemcutter:release # Release gem to Gemcutter rake gemspec # Generate and validates gemspec rake gemspec:debug # Display the gemspec for debugging purposes rake gemspec:generate # Generates the gemspec, using version from VERSION rake gemspec:validate # Validates the gemspec rake git:release # Tag a release in Git rake github:release # Release Gem to GitHub rake install # Install gem using sudo rake rdoc # Build the rdoc HTML Files rake release # Release gem rake rerdoc # Force a rebuild of the RDOC files rake test # Run tests rake version # Displays the current version rake version:bump:major # Bump the gemspec by a major version. rake version:bump:minor # Bump the gemspec by a minor version. rake version:bump:patch # Bump the gemspec by a patch version. rake version:write # Writes out an explicit version.
UPDATE:
Saya menambahkan penjelasan bagaimana membuat gem hello-world executable sehingga bisa dieksekusi langsung dari command line. Berikut ini adalah langkah-langkahnya.
1. Buat direktori bin
2. Buat file hello-world dan tuliskan kode ruby di-dalamnya.
# bin/hello-world puts "this is executable hello-world"3. JIka di Linux, ubah permission.
chmod 755 bin/hello-world4. Ubah Rakefile
Jeweler::Tasks.new do |gem|
gem.name = "hello-world"
gem.summary = "one-line summary of your gem"
gem.description = "longer description of your gem"
gem.email = "youremail@example.com"
gem.homepage = "http://github.com/kuntoaji/hello-world"
gem.authors = ["firsname lastname"]
gem.executables = ["hello-world"] # ------------> add this line
end
5. Commit perubahan.git add . git commit -am "making executable hello-world"6. Rilis gem!
rake gem:bump:major rake release7. Install
gem install hello-world8. Cara penggunaan.
aji@slacky:~$ hello-world this is executable hello-world9. Selesai.
0 comments:
Poskan Komentar