rubyã§ã³ã¼ããæ¸ãã¦ãã¨ã©ã¤ãã©ãªã®ãã¹ã ã¨ãï¼ã¢ã¸ã¥ã¼ã«ã®ä¾åé¢ä¿ã¨ãããã©ããããªã£ã¦ããï¼ãã¨Githubãªã©ã«ç½®ãã¦ãããããªãï¼github ã«ã³ã¼ããç½®ãã¦gem ããã±ã¼ã¸ã«ãããï¼*1ã©ã¤ãã©ãªã®ãã¼ããã¹ã解決ããã
2011-05-17追è¨
rubygems ã®ãã¼ã¸ãè¦ãã¨, jeweler /gem push ã§ããã£ã¦æ¸ãã¦ãã£ãã
http://help.rubygems.org/kb/gemcutter/publishing-your-own-rubygem
gem ãä½ããªã以ä¸ã®ãç§ã®è¨äºã®ããæ¹ã§æ§ããªãã§ããrubygemsã«å ¬éãããªãä¸è¨URLã«å¾ãæ¹ãè¯ãã§ãï¼
gemã®ä½ãæ¹
ã»gemä½æç¨ã®ããã±ã¼ã¸ãã¤ã³ã¹ãã¼ã«
ã»Gemã®ååã決ãã
ã»Gemã®ã²ãªå½¢ãä½ã
ã»ç©ºã£ã½ã®ããã±ã¼ã¸ãä½ã£ã¦ã¿ã
ã»Libã«ã½ã¼ã¹ãæ¸ã
ã»ãã¹ãã®ã½ã¼ã¹ãæ¸ã
ã»ãã¹ããå®è¡ãã
ã»ããã±ã¼ã¸ä½æ
Gemä½æç¨ããã±ã¼ã¸ newgem ãã¤ã³ã¹ãã¼ã«
$ gem install rubyforge $ gem install newgem
ããã§ããããã¢ã¸ã¥ã¼ã«çªã£è¾¼ãã§ãããï¼
Gemã®ã²ãªå½¢ãä½ã newgemã³ãã³ã
ä»åã¯nodaã¨è¨ãååã®ããã±ã¼ã¸ãä½ãã¾ãï¼ *2
$ newgem noda
Rakefileã®FIXMEãç·¨éãã
self.developer 'takuya_1st', '[email protected]' self.post_install_message = 'PostInstall.txt' self.rubyforge_name = self.name # TODO this is default value # self.extra_deps = [['activesupport','>= 2.0.2']]
README.rdocã®FIXMEãç·¨éãã
Copyright (c) 2011 takuya_1st
ããã±ã¼ã¸ãä½ã
ã¾ãã¯ãªã«ããªã空ã£ã½ã®ããã±ã¼ã¸ãä½ã£ã¦ã¿ã¾ãï¼
$ rake package
ç°¡å!!
ãã¹ããæ¸ã
test_helper.rb ããã¹ã¦ã®åºæ¬ã«ãªãã
test_helper.rbã«æ¬¡ã®è¡ã追å
require 'stringio' require 'test/unit' require 'rubygems' require 'drb/drb' require File.dirname(__FILE__) + '/../lib/noda' ##ãã以ä¸ã«libã«ãããã½ã¼ã¹ã追è¨ãã require 'noda' #ãã¹ãã§ä½¿ãããã±ã¼ã¸ããã¼ããã require 'noda/table' # include Noda #include ã¯åã好ãã§å ¥ãã¦ã¾ã
ãã¹ããã¡ã¤ã«ã®æ¸ãæ¹
ãã¹ããã¡ã¤ã«ã§ã¯å ã»ã©ã®ãã«ãã¼ãèªã¿è¾¼ãã§ããã°ãã
ãã¹ããã¡ã¤ã«ã®ä¾
test_table.rb
require File.dirname(__FILE__) + '/test_helper.rb' class TestPageList < Test::Unit::TestCase def test_table_put
ä¸è¨ã®ããã«helperããã¹ããã¡ã¤ã«ããèªã¿è¾¼ãã°ããï¼
ãã¹ãã®å®è¡
$ rake test
rakeã§ãã¹ããå®è¡ããï¼rake便å©ï¼
ã©ã¤ãã©ãªã®ä½æ
["./lib", "./lib/noda"]ã®äºã¤ã®ãã£ã¬ã¯ããªãä½ããã¦ããã
./lib/noda.rb âããã¯ãã¢ã¸ã¥ã¼ã«å¿
é ã©ã¤ãã©ãªãå
±éèªã¿è¾¼ã¿ç¨ã«ä½¿ãã¿ããï¼
ã¢ã¸ã¥ã¼ã«ãèªè¾¼ã®ã²ãªå½¢ãä½ã£ã¦ãã£ãã便å©ãã¼
./lib/noda âããã«ã³ã¼ããæ¸ãã¦ããã
./lib/noda.rb
$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__))) module Noda VERSION = '0.0.1' end
èªåã®æ¸ããã©ã¤ãã©ãªã®ç½®ãå ´æ
./lib/noda/my_class.rbã®ããã«æ¸ãã¦ããã¾ãï¼
èªåãæ¸ãã¨ãã¯ä¸é層ä¸ãã¦lib/noda以ä¸ã«ãã¡ã¤ã«ãæ¸ãã¦ããã¾ãï¼
module Noda class MyClass def initialize #do something end end end
ã®ããã«æ¸ãã¦ãã
ã³ãã³ããä½ãã«ã¯
./script/generate ã³ãã³ãã§ã²ãªå½¢ãä½ãã¾ãï¼
$ ./script/generate executable my_command_name create bin create lib/my_command_name create bin/my_command_name create lib/my_command_name/cli.rb exists test create test/test_my_command_name.rb
ãããããã¡ã¤ã«ãã§ããããã®ã§ãlib/my_command_name/cli.rb ã«ã³ãã³ãã®å®ä½ãæ¸ãã¨è¨ãï¼
ã§ãããã£ãã rake package
ã½ã¼ã¹ã³ã¼ããåºæ¥ãã
rake package
ãã¦ã§ããããã§ãï¼
åèè³æ
å 人ã«æè¬ã§ãï¼
bear.mini : [Ruby] gem の作り方 (1) 導入編
bear.mini : [Ruby] gem の作り方 (2) ひな形を作る
bear.mini : [Ruby] gem の作り方 (3) コードを書く
RubyGems パッケージの作り方 - rubyforge 登録まで - 2nd life