JRubyで相対パスを含む場合に、Jarファイルの中のファイルを読めるようにするためのモンキーパッチの最新版です。

   1  def cleanup_path(path)
   2    if path.to_s.match(/^file:/) && path.is_a?(String)
   3      jar_path, inner_path = path.split('!', 2)
   4      inner_path = File.expand_path(inner_path)
   5      path = [jar_path, inner_path].join('!')
   6    end
   7    path
   8  end
   9  
  10  alias :require_original :require
  11  def require(path)
  12    require_original cleanup_path(path)
  13  rescue Exception => e
  14    raise e unless path.to_s.match(/^file:/)
  15  end
  16  
  17  alias :load_original :load
  18  def load(path)
  19    load_original cleanup_path(path)
  20  rescue Exception => e
  21    raise e unless path.to_s.match(/^file:/)
  22  end
  23  
  24  class Dir
  25    class << self
  26      alias :aref_original :[]
  27      def [](*args)
  28        aref_original *(args.map{|path| cleanup_path(path)})
  29      end
  30    end
  31  end
  32  class File
  33    class << self
  34      alias :mtime_original :mtime
  35      def mtime(path)
  36        if path.match(/^file:/)
  37          jar_file, = path.split('!', 2)
  38          path = jar_file.sub(/^file:/, '')
  39        end
  40        mtime_original(path)
  41      end
  42    end
  43  end

posted by Png genki on Tue 21 Apr 2009 at 02:43
Contents
require_fix.rb 最新版
Comments
瀧内元気: MacOS版は以下にあります * [genki/ViMouse](https://githu... '23-1
dsjf: https://gist.github.com/6bf1bf2c3cbb5eb6e7a7 これ... '13-1
瀧内元気: おお、チェックしてみます。thx! '11-12
overisland: Reeder for iPhone もこの UI を実装していますね。 '11-12
瀧内元気: その情報は見たのですが、以下のサイトによると、現在はまた必要になってるっぽいんですよね。 ... '11-12
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ