• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

Gemを作るのが面倒になってきたので、githubから直接requireできたら楽になるかもしれないと思い、試してみました。

   1  def git(uri, sha1, options = {})
   2    require "tmpdir"
   3    basename = File.basename(uri)
   4    outdir = File.join(Dir.tmpdir, basename, sha1)
   5    unless File.exist?(outdir)
   6      sh = proc{|command| IO.popen("#{command} 2>&1"){|io| io.read}}
   7      sh["git clone #{uri} #{outdir}"]
   8      sh["cd #{outdir}; git checkout #{sha1}"]
   9    end
  10    $:.unshift File.join(outdir, 'lib')
  11    require options[:require_as] || basename.split(/\.git$/)[0]
  12  end

Dir.tmpdirを使ってOSのテンポラリディレクトリの下にリポジトリをクローンしてきて、指定したリビジョンをcheckoutし、LOAD_PATHに"lib"を加えて、リポジトリ名のファイルをrequireしています。

意外と普通にgemの代わりに使える感じです。

posted by Png genki on Thu 16 Jul 2009 at 17:40

Comments:

or Preview
Social Bookmarks
  • Delicious
  • B_entry1552
  • Clip_16_12_w
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ