cutagemを修正してみたりした
rubyをちゃんと勉強しようと思って、先週くらいからruby-1.9.1をちょこちょこと弄ってたんだけど、せっかくなのでgemの作り方も覚えようと思ってcutagemってやつを使ってみた。
OS: Mac OS 10.6
ruby: 1.9.1p243
$ gem sources -a http://gems.github.com $ sudo gem install genki-cutagem
インストールは問題なかったんだけど、いざ使ってみたら
$ cutagem testapp /usr/local/lib/ruby/1.9.1/pathname.rb:969:in `glob': can't convert Pathname into String (TypeError) from /usr/local/lib/ruby/1.9.1/pathname.rb:969:in `glob' from /usr/local/lib/ruby/gems/1.9.1/gems/genki-cutagem-0.0.8.3/lib/cutagem.rb:180:in `select_template'
てな感じでエラーになった。
で、修正内容は以下のとおり。
diff --git a/lib/cutagem.rb b/lib/cutagem.rb index 579d470..60f76fe 100644 --- a/lib/cutagem.rb +++ b/lib/cutagem.rb @@ -108,18 +108,18 @@ class CutAGemCommand begin cp_r template, gemdir, :verbose => true - Pathname.glob(gemdir + "**/gemname*") do |f| + Pathname.glob(gemdir.to_s + "/**/gemname*") do |f| new = f.parent + f.basename.to_s.sub(/gemname/, gemname) puts "Rename #{f.relative_path_from(gemdir)} to #{new.relative_path_from(gemdir)}" f.rename(new) end - Pathname.glob(gemdir + "**/gempath*") do |f| + Pathname.glob(gemdir.to_s + "/**/gempath*") do |f| new = f.parent + f.basename.to_s.sub(/gempath/, gempath) puts "Rename #{f.relative_path_from(gemdir)} to #{new.relative_path_from(gemdir)}" new.parent.mkpath f.rename(new) end - Pathname.glob(gemdir + "**/*") do |f| + Pathname.glob(gemdir.to_s + "/**/*") do |f| next unless f.file? f.open("r+") do |f| content = f.read @@ -168,7 +168,7 @@ class CutAGemCommand templates = [] u_templates = [] if @user_templates.exist? - Pathname.glob(@user_templates + "*").each do |t| + Pathname.glob(@user_templates.to_s + "/*").each do |t| t = [".cutagem/templates/#{t.basename}", t] if t[1].basename.to_s == "default" u_templates.unshift(t) @@ -177,7 +177,7 @@ class CutAGemCommand end end end - Pathname.glob(@templates + "*").each do |t| + Pathname.glob(@templates.to_s + "/*").each do |t| t = ["#{t.basename}", t] if t[1].basename.to_s == "default" templates.unshift(t)
Dir.globの問題だと思うけど、1.9ではStringにしてから渡してやらないとエラーになるようです。
一応変更後もruby-1.8.6でも動作した(ような気がする)ので多分大丈夫かと。
なんか流れで初めてgitとかgithubとか使ってみたりした。
forkしてみたり、commitしてみたり。